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. 大话java基础知识一之为什么java的主函数入口必须是public static void

    为什么java的主函数入口必须是public static void main (String[] args); 很多写javaEE好几年的程序员经常会记得java的主函数就是这么写的,但实际上为什么 ...

  2. jQuery 判断文本输入框的事件

    1.实现以下需求: 输入框中输入内容,发表按钮变为蓝色背景,删除为空则变为原来的颜色 代码实现:通过判断event.target.value是否为空 2.input事件:文本输入框正在输入时生效  f ...

  3. svg的基本图形与属性【小尾巴的svg学习笔记1】

    因为项目有可能用到, 所以学习了一下,做此笔记,图截自慕课网,侵删. 一.基本图形 1.矩形 x,y定义矩形的左上角坐标: width,height定义矩形的长度和宽度: rx,ry定义矩形的圆角半径 ...

  4. Miner3D 数据分析软件

    现在,越来越多的专业人士愿意选择Miner3D来帮助他们进行快速高效的智能决策,因为它是一个功能强大.专业性强.海量数据存储能力.三维可视化效果逼真的数据分析解决工具.Miner3D凭借出色的图形质量 ...

  5. 【从业余项目中学习1】C# 实现XML存储用户名密码(MD5加密)

    最近在写一个C#的项目,用户需求是实现Winform的多文档界面与Matlab算法程序之间的交互.做了一段时间发现,这既能利用业余时间,实战中也可学习一些技术,同时刚毕业也增加一份收入.所以后面会不断 ...

  6. Go编程语言学习笔记

    go如何组织代码?它有一个工作空间的概念.所谓工作空间其实就是一个目录,其中包含三个子目录. src目录包含Go的源文件,它们被组织成包(每个目录都对应一个包), pkg目录包含包对象, bin目录包 ...

  7. SharePoint 2010 究竟需要占用多少服务器资源?

    SharePoint 安装目录(即SharePoint Root)大约 300M 磁盘空间. SharePoint Config 数据库,60M. Admin Center 数据库,100M. 默认安 ...

  8. java中空字符串、null的区别

    String 的null,或者赋值为"",有什么区别? 废话少说,上代码: public class EmptyAndNull { /** * @param args */ pub ...

  9. vs2008使用mysql链接错误

    原因是因为安装了64位的mysql,而开发工具室32位的,需要安装32位的开发库就可以了

  10. 323. Number of Connected Components in an Undirected Graph (leetcode)

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...