Codeforces Round #292 (Div. 1) B. Drazil and Tiles (similar topologies)

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/516/B

A n*m square, ' * ' cannot be filled. Give you a lot of 1*2 angle brackets and ask if you can fill the squares with a single fill.

Like Topsort, '. ' Connected to the '. ' in the upper and lower sides. The point from the degree of 1 as a breach.

1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <queue>9#include <cmath>Ten#include <ctime> One#include <list> A#include <Set> -#include <map> - using namespacestd; thetypedefLong LongLL; -typedef pair <int,int>P; - Const intN = 2e3 +5; - intN, m, tx[] = {-1,0,1,0}, ty[] = {0, -1,0,1}; + CharStr[n][n]; - intdu[n*N]; +Vector <int> g[n*N]; AInlineBOOLJudgeintXinty) { at     if(x >=0&& x < n && y >=0&& y < m && str[x][y] = ='.') -         return true; -     return false; - } -Inlinevoid Get(intXinty) { -      for(inti =0; I <4; ++i) { in         intxx = x + tx[i], yy = y +Ty[i]; -         if(judge (xx, yy)) { toG[x*m + y].push_back (xx*m +yy); +Du[x*m + y]++; -         } the     } * } $InlinevoidChangeintXinty) {Panax Notoginseng     if(M = =1) { -         if(X <y) { thestr[x][0] ='^'; +str[y][0] ='v'; A}Else { thestr[x][0] ='v'; +str[y][0] ='^'; -         } $}Else { $         if(x-y = =-m) { -STR[X/M][X%M] ='^'; -STR[Y/M][Y%M] ='v'; the}Else if(X-y =m) { -STR[X/M][X%M] ='v';WuyiSTR[Y/M][Y%M] ='^'; the}Else if(x-y = =-1) { -STR[X/M][X%M] ='<'; WuSTR[Y/M][Y%M] ='>'; -}Else { AboutSTR[X/M][X%M] ='>'; $STR[Y/M][Y%M] ='<'; -         } -     } - } A  + intMain () the { -     intCNT =0, op =0; $scanf"%d%d", &n, &m); the      for(inti =0; I < n; ++i) { thescanf"%s", Str[i]); the     } the      for(inti =0; I < n; ++i) { -          for(intj =0; J < M; ++j) { in             if(Judge (I, J)) { the                 Get(i, j); the++op; About             } the         } the     } theQueue <int>que; +      for(inti =0; i < n*m; ++i) { -         if(Du[i] = =1) the Que.push (i);Bayi     } the      while(!Que.empty ()) { the         intU =Que.front (); - Que.pop (); -du[u]--; the          for(inti =0; I < g[u].size (); ++i) { the             intv =G[u][i]; thedu[v]--; the             if(Du[v] >0) { -cnt++; the                  for(intj =0; J < G[v].size (); ++j) { thedu[g[v][j]]--; the                     if(Du[g[v][j]] = =1) {94 Que.push (G[v][j]); the                     } the                 } theDU[V] =0;98 Change (U, v); About}Else if(Du[v] = =0) { -cnt++;101 Change (U, v);102             }103         }104     } the     if(CNT *2==op) {106          for(inti =0; I < n; ++i) {107printf"%s\n", Str[i]);108         }109}Else { theprintf"Not unique\n");111     } the     return 0;113}
View Code

Codeforces Round #292 (Div. 1) B. Drazil and Tiles (similar topologies)

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.