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 ;
}

最新文章

  1. java深入技术九 (注解)
  2. 跟我一起学JQuery插件开发
  3. Java比C++好在哪儿?
  4. SQL语句在数据库中是如何执行的
  5. hdu 4778
  6. seajs 学习笔记
  7. Introduction to REST #Reprinted#
  8. 51nod 1020 逆序排列 DP
  9. Dynamics CRM Form表单中通过javascript抓取触发change事件字段的属性名
  10. radio日志sim卡信号状态分析
  11. vue_v-for_遍历数组_遍历对象
  12. Linux交换Esc和Caps
  13. ELK基础原理
  14. Centos下堡垒机Jumpserver V3.0环境部署完整记录(1)-安装篇
  15. Single VIP LLB and SLB config
  16. 邮件相关协议及JavaMail 包简介
  17. delphi存取图片
  18. luogu P3369 【模板】普通平衡树(splay)
  19. 【JavaScript】2013年人气最高的JavaScript框架排名
  20. iOS开发中UILocalNotification本地通知实现简单的提醒功能

热门文章

  1. java保留有效数字
  2. JS nodeType返回类型
  3. UVA 536 (13.08.17)
  4. [Ionic] Build and Run an Ionic App from Scratch
  5. Rss 的作用 及使用方法
  6. java判断数据类型两种方式
  7. EffectiveC#17--装箱和拆箱的最小化
  8. 面试前的准备---C#知识点回顾----03
  9. C#管理IIS中的站点
  10. java基础知识4