Drazil created a following problem about putting 1 × 2 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 (1 ≤ n, m ≤ 2000).

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 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.

Examples

Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
2 4
*..*
....
Output
*<>*
<><>
Input
1 1
.
Output
Not unique
Input
1 1
*
Output
*

Note

In the first case, there are indeed two solutions:

<>^
^*v
v<>

and

^<>
v*^
<>v

so the answer is "Not unique".

题意:输入一个n*m包括'*'和'.'的矩阵,'.'表示该位置为空。'*'表示该位置已有东西。用一个1*2的瓷砖去填满空位置,如果只有一种方法,输出该方法。如果无解或有2种以上的方法输出Not unique.

题解:类似于拓扑排序的想法,将四周只有一个 ' . ' 的点放进队列,之后跑完队列里面所有的点就可以了,在跑的时候,确定另一块砖的时候要将其四周的点的b数组更新,之后队列为空后验证是否可以将所有的地都铺满

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdlib>
#include<vector>
#include<string>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
const double PI = acos(-1.0);
const int maxn = 2e3+;
const int mod = 1e9+; int dx[] = {,,,-};
int dy[] = {,-,,};
int n,m;
char a[maxn][maxn];
int b[maxn][maxn];
struct Node {
int x,y;
};
queue<Node>que;
int Count(int x,int y) //计算每一个点的四周的.的数量
{
int ans = ;
for(int i=;i<;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if(xx>= && xx<n && yy>= && yy<m && a[xx][yy]=='.')
ans++;
}
return ans;
}
void update(int x,int y) //重新数四周只有一个.的点放进队列
{
for(int i=;i<;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if(xx>= && xx<n && yy>= && yy<m && a[xx][yy]=='.')
{
b[xx][yy]=Count(xx,yy);
if(b[xx][yy] == )
que.push(Node{xx,yy});
}
}
}
bool check() //判断是否可以将全部的.都填满
{
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(a[i][j] == '.')
return false;
return true;
}
int main()
{ scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%s",a[i]);
Node node;
memset(b,,sizeof b);
while(!que.empty())
que.pop();
for(int i=;i<n;i++) //将四周只有一个.的放进队列
{
for(int j=;j<m;j++)
{
if(a[i][j] == '*')
continue;
b[i][j] = Count(i,j);
if(b[i][j] == )
{
node.x = i;
node.y = j;
que.push(node);
}
}
}
while(!que.empty()) //类拓扑
{
node = que.front();
que.pop();
int x = node.x;
int y = node.y;
for (int i = ; i < ; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= && nx < n && ny >= && ny < m && a[nx][ny] == '.') {
if (i == ) {
a[x][y] = '<';
a[nx][ny] = '>';
} else if (i == ) {
a[x][y] = '>';
a[nx][ny] = '<';
} else if (i == ) {
a[x][y] = '^';
a[nx][ny] = 'v';
} else if (i == ) {
a[x][y] = 'v';
a[nx][ny] = '^';
}
update(x, y);
update(nx, ny);
break;
}
}
}
if(check())
{
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
}
else
puts("Not unique"); }

Drazil and Tiles CodeForces - 516B (类拓扑)的更多相关文章

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

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

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

  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 516B Drazil and Tiles 其他

    原文链接http://www.cnblogs.com/zhouzhendong/p/8990658.html 题目传送门 - CodeForces 516B 题意 给出一个$n\times m$的矩形 ...

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

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

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

  7. 【codeforces 516B】Drazil and Tiles

    题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...

  8. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

  9. [ CodeForces 515 D ] Drazil and Tiles

    \(\\\) \(Description\) 给出一个\(N\times M\) 的网格,一些位置是障碍,其他位置是空地,求是否存在一个用 \(1\times 2\)的骨牌铺满空地的方案,以及方案是否 ...

随机推荐

  1. dos命令执行mysql的sql文件

    1.cmd进入dos窗口 2.输入cd+ mysql的bin目录后进入bin文件下 3.进入控制台:mysql -uroot -proot  回车 4.选择数据库:use mydata go 回车 5 ...

  2. AngularJS 指令解析(二)

    AngularJS 指令解析(二) 第一篇我们讲过了作用域(scope)这块内容,现在我们进入正题,讲AngularJS的指令. 什么是指令? 这里我们引用官方的一句话: Custom directi ...

  3. appium-python-api中文文档

    来自https://wenku.baidu.com/view/533603ce581b6bd97e19eaa1.html mark,同时提供给需要使用python写脚本的童鞋们

  4. 怎样解决putty终端乱码的方法

    原文地址:https://jingyan.baidu.com/article/3aed632e5f00ae701080913a.html?qq-pf-to=pcqq.c2c 终端输入:echo $LA ...

  5. 关于java中的hashcode和equals方法原理

    关于java中的hashcode和equals方法原理 1.介绍 java编程思想和很多资料都会对自定义javabean要求必须重写hashcode和equals方法,但并没有清晰给出为何重写此两个方 ...

  6. aaS软件的必要特征分析,一定是多租户特性吗

    本篇文章讲述了SaaS软件的必要特征一定是多租户特性?对于许多小型企业来说,SaaS是采用先进技术的最好途径,它消除了企业购买.构建和维护基础设施和应用程序的需要 课课家教育平台提醒各位:本篇文章纯干 ...

  7. sublim的正则匹配(待续)

    ctrl+H 打开匹配模式 打开正则匹配模式 正则匹配的一些方法:  点代表的是任意字符.* 代表的是取 0 至 无限长度问号代表的是非贪婪模式.三个链接在一起是取尽量少的任意字符,一般不会这么单独写 ...

  8. SQL:获取语句执行时间2

    获取sql执行时间方法2 --清除缓存 CHECKPOINT; DBCC DROPCLEANBUFFERS; DBCC FREEPROCCACHE; DBCC FREESYSTEMCACHE ('AL ...

  9. 【JavaScript 封装库】BETA 1.0 测试版发布!

    /* 源码作者: 石不易(Louis Shi) 联系方式: http://www.shibuyi.net =============================================== ...

  10. TCP的可靠连接是如何产生的?

    http://bbs.csdn.net/topics/190011812 看过TCP/IP的源代码没?tcp中所谓的连接只是在tcp的tcb中存储了对端的地址信息,并且记录连接的状态,通过重发之类的来 ...