"CF 515D" Drazil and Tiles

Source: Internet
Author: User

"CF 515D" Drazil and Tiles

The idea of a topology if it satisfies the condition '. ' There must be a 1 point before the end of the traverse (there is only one '. ' On the left and right)

When traversing to a 1-degree point u, enclose the point V with which he is connected with the corresponding parentheses, and V is also matched to zero at the same time the rest of the point in the V-in minus 1 is continuously traversed know to traverse all '. '
If it can be traversed, then the condition is not solved or many solutions are satisfied.
(Spit out the original use of pure topological thinking is also absolutely to T's. Later changed BFS

The code is as follows:

#include <iostream>#include <cstdio>#include <cstdlib>#include <queue>using namespace STD;typedef structpoint{intx, y;} Point; Point pt[4000000];intin[2002][2002];Charmp[2002][2002];intDirx[] = {0,0,1,-1};intDiry[] = {1,-1,0,0};CharCh[] ="><v^";CharSt[] ="<>^v";intM,n;intTpBOOLIinintXintY) {returnX >0&& x <= m && y >0&& y <= N;}voidRushintXintY) {inti,xx,yy,cnt =0; for(i =0; I <4;        ++i) {xx = x+dirx[i]; yy = Y+diry[i];if(Iin (XX,YY) && mp[xx][yy] = ='. ') cnt++; } In[x][y] = cnt;}BOOLTopo () {inti,j,k,x,y,xx,yy,xxx,yyy,cnt =0; queue <pair<int,int>> q; for(j =0; J <tp;        ++J) {x = pt[j].x; y = pt[j].y;if(In[x][y] = =1) {Q.push (pair<int,int> (x, y)); In[x][y] =0; }} Pair <int,int> P; while(!q.empty ())        {p = Q.front ();        Q.pop ();        x = P.first;        y = P.second; in[x][y]--; for(j =0; J <4;            ++J) {xx = x+dirx[j]; yy = Y+diry[j];if(Iin (XX,YY) && mp[xx][yy] = ='. ') {In[xx][yy] =0;                MP[XX][YY] = Ch[j]; Mp[x][y] = St[j]; for(k =0; K <4;                    ++k) {xxx = xx+dirx[k]; YYY = Yy+diry[k];if(Iin (XXX,YYY) && mp[xxx][yyy] = ='. ') {Rush (xxx,yyy);if(IN[XXX][YYY] = =1) Q.push (pair<int,int> (xxx,yyy)); }} cnt+=2; }        }    }returnCNT = = TP;}intMain () {intI,j;scanf("%d%d", &m,&n); TP =0; for(i =1; I <= m; ++i) {scanf('%s ', mp[i]+1); for(j =1; J <= N; ++J)if(Mp[i][j] = ='. ') {pt[tp].x = i;                Pt[tp++].y = j; IN[I][J] =0;if(Iin (i1, j) && mp[i-1][J] = ='. ') {in[i-1][j]++;                in[i][j]++; }if(Iin (i,j-1) && mp[i][j-1] =='. ') {in[i][j-1]++;                in[i][j]++; }            }    }if(Topo ()) { for(i =1; I <= m; ++i)printf("%s\n", mp[i]+1); }Else puts("Not unique");return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"CF 515D" Drazil and Tiles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.