【题目链接】: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的更多相关文章

  1. 【codeforces 516B】Drazil and Tiles

    题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...

  2. 【codeforces 515C】Drazil and Factorial

    [题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...

  3. 【codeforces 515B】Drazil and His Happy Friends

    [题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...

  4. 【codeforces 515A】Drazil and Date

    [题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. strok函数用法【转】

    本文转载自:http://blog.csdn.net/hexiechina2010/article/details/25096763 char *strtok( char *strToken, con ...

  2. Chrome格式化JavaScript

    在network或者source的tab中找到对应的JavaScript文件 重点在右下角的{}图标,点击一下,就会帮你自动格式化了 https://plus.google.com/+AddyOsma ...

  3. hdu 1512 Monkey King —— 左偏树

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1512 很简单的左偏树: 但突然对 rt 的关系感到混乱,改了半天才弄对: 注意是多组数据! #includ ...

  4. istio-禁用/允许sidecar设置

    一.在namespace设置自动注入: 给 default 命名空间设置标签:istio-injection=enabled: $ kubectl label namespace default is ...

  5. codevs1258 关路灯(☆区间dp)

    1258 关路灯  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master     题目描述 Description 多瑞卡得到了一份有趣而高薪的工作.每天早晨他必须 ...

  6. 微信小程序压缩图片并上传到服务器(拿去即用)

    这里注意一下,图片压缩后的宽度是画布宽度的一半 canvasToTempFilePath 创建画布的时候会有一定的时间延迟容易失败,这里加setTimeout来缓冲一下 这是单张图片压缩,多张的压缩暂 ...

  7. ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod

    因为突然要用到cocospod,突然发现在使用pod install的时候出现 -bash: pod: command not found 我去-不知道为什么,然后我就想重新安装下cocospod,在 ...

  8. BZOJ 4811 树链剖分+线段树

    思路: 感觉这题也可神了.. (还是我太弱) 首先发现每一位不会互相影响,可以把每一位分开考虑,然后用树链剖分或者LCT维护这个树 修改直接修改,询问的时候算出来每一位填0,1经过这条链的变换之后得到 ...

  9. post提交表单的数据查看方式(不是很理解,但要会看,可以找人商讨下,比如崔老师,自己再看一遍HTTP基础)

  10. JVM之旅------jvm内存模型

    JVM内存管理机制 Java与C++之间有一堆由内存动态分配与垃圾收集技术所围成的“高墙”,墙外面的人想进去,墙里面的人却想出来. —— <深入理解Java虚拟机:JVM高级特性与最佳实践> ...