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

Input
...
.*.
...
Output
Not unique
Input
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
*..*
....
Output
*<>*
<><>
Input
.
Output
Not unique
Input
*
Output
*

Hint

In the first case, there are indeed two solutions:

<>^
^*v
v<>
and ^<>
v*^
<>v
so the answer is "Not unique".

Source

 
用贪心法解决:首先应该着力填充周围只有一个空格的点,随后以它的空格为中心,再不断向外拓展,直到整个界面被填充。
注意在judge函数判断边界和‘.’时应该这样写:return (i>=0 && i<n && j>=0 && j<m && mp[i][j]=='.');  分开判断一直错。
 #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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)

    题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似t ...

  5. CodeForces - 516B Drazil and Tiles(bfs)

    https://vjudge.net/problem/CodeForces-516B 题意 在一个n*m图中放1*2或者2*1的长方形,问是否存在唯一的方法填满图中的‘.’ 分析 如果要有唯一的方案, ...

  6. 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. ...

  7. Codeforces Round #292 (Div. 1) C - Drazil and Park

    C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...

  8. 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 ...

  9. 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] ...

随机推荐

  1. 【转】DM8168图像处理Link

    1> dei dei 主要做数据交错处理,带缩放 dei control data flow: 2> sclr 8168中支持缩放按比例的分子和分母,只支持缩小,貌似不支持放大,且注意输出 ...

  2. PHP计算一个目录文件大小方法

    <?php $dirfile='../hnb'; /** *计算一个目录文件大小方法 *$dirfile:传入文件目录名 **/ function dirSize($dirfile) { $di ...

  3. Unity UI和引用的管理中心

    我们来谈谈Unity的UI, 通常会写一些UI页面,当A页面需要去操作B页面的时候. 至少要获取B页面的引用吧! 一般新人都会在组件的写一个public GameObject UIB页面的属性, 然后 ...

  4. pod setup 报CocoaPods was not able to update the `master` repo 错误解决办法

    先删除全局的缓存: $ sudo rm -fr ~/Library/Caches/CocoaPods/ $ sudo rm -fr ~/.cocoapods/repos/master/ 还不行的话就把 ...

  5. Swift——(一)为Swift内置类型加入属性

    在看苹果官方的Swift Language的时候,遇到实验:Write an extension for the Double type that add an absoluteValue prope ...

  6. map的类型映射

    以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题. 以下是C++源码,比较简短,容易理解的. #include " ...

  7. PHP学习笔记三十六【try 二】

    <?php //定义一个顶级异常处理器 要定义在最上面 function my_exception($e) { echo "我是顶级异常处理:".$e->getMess ...

  8. Xcode 常用快捷键及代码自动排版 二

    Xcode常用快捷键,网上找的总结一下,特别是格式化代码 隐藏xcode command+h退出xcode command+q关闭窗口 command+w关闭所有窗口 command+option+w ...

  9. POJ 1269 - Intersecting Lines 直线与直线相交

    题意:    判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...

  10. 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...