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. pyqt labe界面超级链接例子学习

    def bz(self): self.lable1=QtGui.QLabel(u'<br><a href=http://windows.microsoft.com/zh-cn/win ...

  2. pyqt QTimer,QThread例子学习

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from PyQ ...

  3. openldap---ldapsearch使用

    ldapsearch 參数表 下表描写叙述能够用于 ldapsearch 的区分大写和小写的參数. 參数 用途 -? 打印关于使用 ldapsearch 的帮助. -a deref 指定别名反向引用. ...

  4. [置顶] 正则表达式应用:匹配IP地址

    都知道iP地址有四个数值,三个点号组成.三个数值的具体范围为0到255,为了使用正则表达式匹配就必须分析IP地址的组成 1先分析数值,2再组合数值和点号 1先分析数值 IP地址的数字范围从0到255, ...

  5. CLR via C# - Char_String - Format

    //前面那个本来想重新编辑的,但是那个编辑器之前被我调到Markdown之后,改回Tiny MCE编辑器不出来 1.ToString()方法 & IFormattable & IFor ...

  6. 移动开发(webapp)过程中的小细节总结

    1.阻止旋转屏幕时自动调整字体大小 html, body, form, fieldset, p, div, h1, h2, h3, h4, h5, h6 { -webkit-text-size-adj ...

  7. vue中关于computed的一点理解

    computed相当于属性的一个实时计算,如果实时计算里关联了对象,那么当对象的某个值改变的时候,同事会出发实时计算. 例子: <body id="content"> ...

  8. struts2 实现过程和xml配置

    实现过程: 当Web容器收到 请求(HttpServletRequest)它将请求传递给一个标准的的过滤链包括 (ActionContextCleanUp)过滤器,然后经过Other filters( ...

  9. 深入C语言内存区域分配(进程的各个段)详解(转)

    原文地址:http://www.jb51.net/article/39696.htm 一般情况下,一个可执行二进制程序(更确切的说,在Linux操作系统下为一个进程单元,在UC/OSII中被称为任务) ...

  10. linux下virtualenv的python版本

    virtualenv是python开发中一个重要的工具,它可以帮助我们创建一个干净的python解释环境,创建虚拟环境时,这个虚拟环境的 python版本往往是系统默认的2.x版本.别急,我们只需要一 ...