【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个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- Entity Framework 4.3 中使用存储过程
尽管 Entity Framework 4.3 都已经发布了,且表示在 EF 5 中性能将会有很大提升.但很多存储过程控,始终不会放弃使用存储过程,那今天就让我们看看在 EF 4.3 中怎么使用存储过 ...
- go 成长路上的坑(1)
一.先来看一段代码 package main import "fmt" type X struct{} func (x *X) test(){ println("h1&q ...
- Boost(1.69.0) windows入门(译)
目录 Boost windows入门 1. 获得Boost源代码 2. Boost源代码组织 The Boost Distribution 3. 仅用头文件的库 Header-Only Librari ...
- yield from (python生成器)
#生成器中的yield from是干什么用的(一般多用于线程,协程那)def func(): # for i in 'AB': # yield i yield from 'AB' # 就相当于上面的f ...
- 最近几道hihocode不会做的题目
几个易错点 1.数据范围一定要开大,一般多开10个或者5个. 2. 从经常写 int a[n], 然后访问a[n], 这显然会下标越界. 3. 浮点数,无法精确的比较,等于,大于,小于, 都需要使用e ...
- ACM_求交集
求交集 Time Limit: 2000/1000ms (Java/Others) Problem Description: 输入集合A和B,按大小顺序输出A和B的交集. Input: 输入包含多组测 ...
- 题解报告:hdu 3790 最短路径问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你起 ...
- 在vSphere Client上安装虚拟机工具VMware Tools
一.什么是虚拟机工具 VMware Tools是一套安装在虚拟机操作系统中的实用程序.VMware Tools可提高虚拟机的性能,并在 VMware产品中实现多个易于使用的功能. 尽管客户机操作系统在 ...
- 使用UAParser在C#MVC项目中如何判断用户是在用什么设备进行访问(手机,平板还是普通的电脑)
现在我们开发的很多web应用都要支持手机等移动设备.为了让手机用户能有更加好的用户体验,我们经常为手机设备专门准备一套前端的页面.这样当用户使用普通电脑来访问的时候,我们的应用就向用户展示普通电脑的页 ...
- 编写高质量的js之恰当选用if和switch
switch结构中存在很多限制,存在这些限制的主要目的是提高多重分支结构的执行效率.因此,如果能够使用switch结构,就不要选择if结构. 无论是使用if结构,还是使用switch结构,应该确保下面 ...