【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个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- Silverlight 2学习笔记一:初识Silverlight
Silverlight,问世至今已有好一段时日了,向来只是只闻其名,不知其实,今天终于对Silverlight有了点初步的了解. 一.Silverlight是什么?Sliverlight是基于.NET ...
- AJAX-responseXML 属性
如果来自服务器的响应是 XML,而且需要作为 XML 对象进行解析,需要使用 responseXML 属性 cd_catalog.xml: <CATALOG><CD><T ...
- 使用免费SSL证书让网站支持HTTPS访问
参考掘金的文章,掘金的文章最详细. https://juejin.im/post/5a31cbf76fb9a0450b6664ee 先检查是否存在 EPEL 源: # 进入目录检查是否存在 EPEL ...
- etcd磁盘清理步骤
etcd默认的空间配额限制为2G,超出空间配额限制就会影响服务,所以需要定期清理 以下是etcd磁盘清理的步骤: 1. 显示空间配额: ETCDCTL_API=3 etcdctl --endpoint ...
- 我眼中的SEO——略读一些SEO书后
近些日子一直在看一些SEO方面的书.为人有些浮躁,读SEO实在读不出太大营养,除了第一本书外,之后的书就是在不停地向后翻页.没有过太具体的实践,现在就来写一下我眼中的SEO.还希望各位多多指教. 1. ...
- Counterfeit Dollar
http://poj.org/problem?id=1013 #include<stdio.h> #include<string.h> #include<math.h&g ...
- C# 工厂单例
public class BusinessFactory { private static BusinessFactory instance = null; pri ...
- Codeforces 455D 分块+链表
题意: 给定一个长度为 N 的序列两种操作1 l r 将[l,r]的数向右循环移位 2 l r 询问[l,r]内有多少个数等于 k其中 N,Q≤105,ai≤N 强制在线 思路: 1. 每块用一个链表 ...
- UNIX环境高级编程--8. 进程控制
进程控制进程标识: 每一个进程都有一个非负整型表示的唯一进程ID.虽然唯一,但是ID可以复用.当一个进程结束后,其进程ID会被延迟复用. ID=0的进程通常是调度进程,常被称作交换进程(s ...
- Web开发中跨域的几种解决方案
同domain(或ip),同端口,同协议视为同一个域,一个域内的脚本仅仅具有本域内的权限,可以理解为本域脚本只能读写本域内的资源,而无法访问其它域的资源.这种安全限制称为同源策略. 出于安全考虑,HT ...