cf516b Drazil and Tiles

网友投稿 686 2022-10-05

cf516b Drazil and Tiles

cf516b Drazil and Tiles

​​ 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写成char格式 网站直接无输出

#include#include#include#define N 2200struct node{ int x1,y1,x2,y2;};std::queue q;int x[5]={0,-1,1,0,0},y[5]={0,0,0,1,-1};bool visit[N][N];char mp[N][N];int n,m;inline void solve(int i,int j){ if(visit[i][j]) return; int cnt=0; if (mp[i][j]=='.'){ for (int z=1;z<=4;++z) if (i+x[z]<=n&&i+x[z]>0&&j+y[z]<=m&&j+y[z]>0){ int x1=i+x[z],y1=j+y[z]; if (mp[x1][y1]=='.'&&!visit[x1][y1]) cnt++; } if (cnt==1){ node tmp;tmp.x1=i;tmp.y1=j; for (int z=1;z<=4;++z) if (i+x[z]<=n&&i+x[z]>0&&j+y[z]<=m&&j+y[z]>0){ int x1=i+x[z],y1=j+y[z]; if (mp[x1][y1]=='.'&&!visit[x1][y1]) tmp.x2=x1,tmp.y2=y1,q.push(tmp),visit[x1][y1]=true,visit[i][j]=true; } } }}inline void solve1(int i,int j){ for (int z=1;z<=4;++z) if (i+x[z]<=n&&i+x[z]>0&&j+y[z]<=m&&j+y[z]>0){ int x1=i+x[z],y1=j+y[z]; if (mp[x1][y1]=='.'&&!visit[x1][y1]) solve(x1,y1); }}int main(){ freopen("cf.in","r",stdin);// freopen("cf.out","w",stdout); scanf("%d%d",&n,&m); for (int i=1;i<=n;++i) scanf("%s",mp[i]+1); for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) if (mp[i][j]=='*') visit[i][j]=true; for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) solve(i,j); while (!q.empty()){ node tmp=q.front();q.pop(); int x1=tmp.x1,x2=tmp.x2,y1=tmp.y1,y2=tmp.y2; if (y1';solve1(x2,y2);continue;} if (y1>y2){mp[x1][y1]='>';mp[x2][y2]='<';solve1(x2,y2);continue;} if (x1x2){mp[x1][y1]='v';mp[x2][y2]='^';solve1(x2,y2);continue;} } for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) if (mp[i][j]=='.') {printf("Not unique");return 0;} for (int i=1;i<=n;++i) printf("%s\n",mp[i]+1); return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:详解SpringBoot定时任务功能
下一篇:luogu1262 间谍网络
相关文章

 发表评论

暂时没有评论,来抢沙发吧~