#292 (div.2) D.Drazil and Tiles (贪心+bfs)
Description
- Drazil created a following problem about putting × tiles into an n × m grid:
- "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."
- But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".
- Drazil found that the constraints for this task may be much larger than for the original task!
- Can you solve this new problem?
- Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.
Input
- The first line contains two integers n and m ( ≤ n, m ≤ ).
- The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.
Output
- If there is no solution or the solution is not unique, you should print the string "Not unique".
- Otherwise you should print how to cover all empty cells with × tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.
Sample Input
- ...
- .*.
- ...
- Not unique
- ..**
- *...
- *.**
- ....
- <>**
- *^<>
- *v**
- <><>
- *..*
- ....
- *<>*
- <><>
- .
- Not unique
- *
- *
Hint
- In the first case, there are indeed two solutions:
- <>^
- ^*v
- v<>
- and
- ^<>
- v*^
- <>v
- so the answer is "Not unique".
Source
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<math.h>
- #include<algorithm>
- #include<queue>
- #include<set>
- #include<bitset>
- #include<map>
- #include<vector>
- #include<stdlib.h>
- #include <stack>
- using namespace std;
- int dirx[]={,,-,};
- int diry[]={-,,,};
- #define PI acos(-1.0)
- #define max(a,b) (a) > (b) ? (a) : (b)
- #define min(a,b) (a) < (b) ? (a) : (b)
- #define ll long long
- #define eps 1e-10
- #define MOD 1000000007
- #define N 2006
- #define inf 1e12
- int n,m;
- char mp[N][N];
- struct Node{
- int x,y;
- };
- char change[]="><<>v^^v";
- bool judge(int i,int j){
- return (i>= && i<n && j>= && j<m && mp[i][j]=='.');
- }
- int nearPoint_num(int x,int y){
- int ans=;//ans表示周围的空点
- for(int i=;i<;i++){
- int tx=x+dirx[i];
- int ty=y+diry[i];
- if(judge(tx,ty)){
- ans++;
- }
- }
- return ans;
- }
- void bfs(){
- queue<Node>q;
- Node tmp;
- Node t1,t2,t3;
- for(int i=;i<n;i++){
- for(int j=;j<m;j++){
- if(judge(i,j) && nearPoint_num(i,j)==){
- tmp.x=i;
- tmp.y=j;
- //printf("***%d %d\n",tmp.x,tmp.y);
- q.push(tmp);
- }
- }
- }
- while(!q.empty()){
- t1=q.front();
- q.pop();
- for(int i=;i<;i++){
- t2.x=t1.x+dirx[i];
- t2.y=t1.y+diry[i];
- if(judge(t2.x,t2.y)){
- mp[t1.x][t1.y]=change[i*];
- mp[t2.x][t2.y]=change[i*+];
- //printf("%d %d %c\n",t1.x,t1.y,mp[t1.x][t1.y]);
- //printf("%d %d %c\n",t2.x,t2.y,mp[t2.x][t2.y]);
- for(int j=;j<;j++){
- t3.x=t2.x+dirx[j];
- t3.y=t2.y+diry[j];
- if(judge(t3.x,t3.y) && nearPoint_num(t3.x,t3.y)==){
- q.push(t3);
- }
- }
- }
- }
- }
- int flag=;
- for(int i=;i<n;i++){
- for(int j=;j<m;j++){
- if(mp[i][j]=='.'){
- flag=;
- break;
- }
- }
- if(flag==){
- break;
- }
- }
- if(flag==){
- printf("Not unique\n");
- }
- else{
- for(int i=;i<n;i++){
- for(int j=;j<m;j++){
- printf("%c",mp[i][j]);
- }
- printf("\n");
- }
- }
- }
- int main()
- {
- while(scanf("%d%d",&n,&m)==){
- for(int i=;i<n;i++){
- scanf("%s",mp[i]);
- }
- bfs();
- }
- return ;
- }
#292 (div.2) D.Drazil and Tiles (贪心+bfs)的更多相关文章
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序
B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...
- Codeforces Round #292 (Div. 1) - B. Drazil and Tiles
B. Drazil and Tiles Drazil created a following problem about putting 1 × 2 tiles into an n × m gri ...
- Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]
传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似t ...
- CodeForces - 516B Drazil and Tiles(bfs)
https://vjudge.net/problem/CodeForces-516B 题意 在一个n*m图中放1*2或者2*1的长方形,问是否存在唯一的方法填满图中的‘.’ 分析 如果要有唯一的方案, ...
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ...
- Codeforces Round #292 (Div. 1) C - Drazil and Park
C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 631 (Div. 2) E. Drazil Likes Heap 贪心
https://codeforces.com/contest/1330/problem/E 有一个高度为h的大顶堆:有2h -1个不同的正整数,下标从1到2h−1,1<i<2h, a[i] ...
随机推荐
- vi命令笔记
vim编辑器 文本编辑器,字处理器ASCII nano, sed vi: Visual Interfacevim: VI iMproved 全屏编辑器,模式化编辑器 vim模式:编辑模式(命令模式)输 ...
- C#Http编程
c# 模拟 网页实现12306登陆.自动刷票.自动抢票完全篇(转) 这一篇文章,我将从头到尾教大家使用c#模拟网页面登陆12306网站,自动刷票,选择订票人,到最后一步提交订单.研究过HTTP协议的童 ...
- Bin & Jing in wonderland(概率,组合数学)
Problem 2103 Bin & Jing in wonderland Accept: 201 Submit: 1048 Time Limit: 1000 mSec Memor ...
- UIImage与UIColor互转
Objective-C UIColor -> UIImage ? 1 2 3 4 5 6 7 8 9 10 11 - (UIImage*) createImageWithColor: (UICo ...
- chart.js制作折线图
<!DOCTYPE html> <html> <head> <title></title> </head> <script ...
- EffectiveC#16--垃圾最小化
1.申请和释放一个基于堆内存的对象要花上更多的处理器时间. 所以当一个引用类型的局部变量在常规的函数调用中使用的非常频繁时应该把它提升为对象的成员(方法一) 2.当你把一个实现了IDisposable ...
- cookie丢失、登陆自动退出问题解决
cookie保存在客户端或者内存中,不易丢失.但是在某些情况下会被忽略.在项目过程中遇到过跨域丢失的情况.在VS里面运行的程序,产生的cookie默认是没有domain值的,但是给它设定domain值 ...
- SqlServer存储过程传入Table参数
今天是周日,刚好有空闲时间整理一下这些天工作业务中遇到的问题. 有时候我们有这样一个需求,就是在后台中传过来一个IList<类>的泛型集合数据,该集合是某个类的实例集合体,然后将该集合中的 ...
- C#winform修改IP,dns
/// 将IP,DNS设置为自动获取 /// private void setDHCP() { string _doscmd = & ...
- js静态方法
1.ajax() 方法是属于“函数”本身的,和返回的对象没有关系 2.bark药调用,必须药new Hashiqi()得到对象,且由返回对象才能调用 3.ajax()方法药调用,不需要new对象,直接 ...