【codeforces 515D】Drazil and Tiles
【题目链接】:http://codeforces.com/contest/515/problem/D
【题意】
给你一个n*m的格子;
然后让你用1*2的长方形去填格子的空缺;
如果有填满的方案且方案是唯一的;
则输出那个方案,否则,输出不唯一;
【题解】
记录每个点的度;
每个点的度,为这个点4个方向上空格的个数;
优先处理度数为1的点;
这些点的摆放方式肯定是唯一的;
摆完这些点(两个之后),与之相连的点的度数都减1;
看看有没有新的度数为1的点;
很像拓扑排序对吧。
最后看看占据的点是不是n*m个
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e3+100;
struct abc
{
int x, y;
};
int n, m,du[N][N],cnt = 0;
char s[N][N];
bool bo[N][N];
queue <abc> dl;
void cl(int x, int y)
{
rep1(j, 1, 4)
{
int x1 = x + dx[j], y1 = y + dy[j];
du[x1][y1]--;
if (bo[x1][y1] && du[x1][y1] == 1)
dl.push({ x1,y1 });
}
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
memset(bo, false, sizeof bo);
rei(n), rei(m);
rep1(i, 1, n)
{
scanf("%s", s[i] + 1);
rep1(j, 1, m)
if (s[i][j] == '.')
bo[i][j] = true;
else
bo[i][j] = false,cnt++;
}
rep1(i,1,n)
rep1(j,1,m)
if (bo[i][j])
{
int num = 0;
rep1(k, 1, 4)
num += bo[i + dx[k]][j + dy[k]];
du[i][j] = num;
if (du[i][j] == 1)
{
dl.push({ i,j });
}
}
while (!dl.empty())
{
int x0 = dl.front().x, y0 = dl.front().y;
dl.pop();
rep1(j, 1, 4)
{
int x = x0 + dx[j], y = y0 + dy[j];
/*
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
*/
if (bo[x][y])
{
if (j == 1) s[x0][y0] = '^', s[x][y] = 'v';
if (j == 2) s[x0][y0] = 'v', s[x][y] = '^';
if (j == 3)s[x0][y0] = '>', s[x][y] = '<';
if (j == 4) s[x0][y0] = '<', s[x][y] = '>';
bo[x][y] = bo[x0][y0] = false;
cl(x, y), cl(x0, y0);
cnt += 2;
break;
}
}
}
if (cnt == n*m)
{
rep1(i, 1, n)
puts(s[i] + 1);
}
else
puts("Not unique");
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 515D】Drazil and Tiles的更多相关文章
- 【codeforces 516B】Drazil and Tiles
题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
- 【codeforces 515B】Drazil and His Happy Friends
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...
- 【codeforces 515A】Drazil and Date
[题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- bzoj 3301 Cow Line
题目大意: n的排列,K个询问 为P时,读入一个数x,输出第x个全排列 为Q时,读入N个数,求这是第几个全排列 思路: 不知道康拓展开是什么,手推了一个乱七八糟的东西 首先可以知道 把排列看成是一个每 ...
- 【SCOI 2011】 糖果
[题目链接] 点击打开链接 [算法] 当x = 1时,连边(a,b,0)和(b,a,0) 当x = 2时,连边(a,b,1) 当x = 3时,连边(b,a,0) 当x = 4时,连边(b,a,1) 当 ...
- [Swift通天遁地]七、数据与安全-(18)使用Swift实现原生的MD5加密
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]八、媒体与动画-(6)使用开源类库快速实现滑入动画
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- composer 下载安装
linux/mac os curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/compos ...
- 前端性能优化---减少http请求数量和减少请求资源的大小
减少http请求数量:就是资源的合并 减少http请求大小:就是资源的压缩 一.资源合并的原理: 资源不合并的缺点: 1.文件和文件之间有插入请求----请求a.js,b.js,c.js(三行 ...
- 【百度之星】-IP聚合
问题描述: Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个 ...
- 转 使用Hibernate操作数据库时报:No CurrentSessionContext configured! 异常
没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:1.本地事务<property name=&q ...
- Android 微信SDK图片分享(checkArgs fail, thumbData is invalid)
微信官网给的Demo中.图片的分享例子他是这么描述的: String url = "http://pic2.nipic.com/20090506/1478953_125254084_2.jp ...
- Linux学习(一)--基本概念
一.Linux概述 Linux是一款全球性的免费的开源的操作系统平台,其特点是实现了多任务多用户处理,主要是依赖内核kernel shell,且占用资源少 (最小配置只要4Mb内存就能运行). 百度百 ...