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. UIView 转 UIImage

    这个方法很实用,特别是在做水印相机得时候... - (UIImage*) imageWithUIView:(UIView*) view{ // 创建一个bitmap的context // 并把它设置成 ...

  2. LinqToXML~读XML文件续

    上篇文章读了如何通过linq to xml去读取XML文件,而这讲主要通过linq to xml来读取由属性组件的XML文件,例如读取一个web.config的XML格式的配置文件,下面是config ...

  3. 关于使用STL常见的两个bug

    1.bug 1 class CTest { public : vector<int> getVector() const //需要写成引用形式,不然下面begin.end调用会以拷贝形式调 ...

  4. [Regex Expression] Confirmative -- World bundry

    String to check: As it turns out, our potential shipmates are extremely superstitious. As such, we d ...

  5. arcengine 调用arctoolbox功能的举例 spatialJoin

    废话不多说,code是王道. 其中str1.str2两个参数是target路径.join路径 private void spatialJoin(Geoprocessor gp, string str1 ...

  6. 4. 绘制光谱曲线QGraphicsView类

    一.前言 Qt的QGraphicsView类具有强大的视图功能,与其一起使用的还有QGraphicsScene类和QGraphicsItem类.大体思路就是通过构建场景类,然后向场景对象中增加各种图元 ...

  7. avalon2学习心得(1)

    github上,avalon2的项目描述是这样的:“avalon2是一款基于虚拟DOM与属性劫持的 迷你. 易用. 高性能 的 前端MVVM框架, 适用于各种场景, 兼容各种古老刁钻浏览器, 吸收最新 ...

  8. java面试大全

    JAVA相关基础知识1.面向对象的特征有哪些方面 1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时 ...

  9. alarm函数可以定时

    貌似是可以的,不过感觉好像这样用不是很好,最好还是用回timer_settimer一些列函数吧,不过既然开了头,就看下alarm怎么用吧. 1. 所需头文件  #include<unistd.h ...

  10. 0112.1——iOS开发之理解iOS中的MVC设计模式

    模型-视图-控制器(Model-View-Controller,MVC)是Xerox PARC在20世纪80年代为编程语言Smalltalk-80发明的一种软件设计模式,至今已广泛应用于用户交互应用程 ...