Problem uva12113-overlapping Squares
accept:116 submit:596time limit:3000 mSec problem Description
Input
The input consists of several test cases. Each test case is a contained in-ve lines and each line contains nine characters. If the horizontal border of a? lled square is visible it's denoted with "(ASCII value) sign and if vertical border of a? lled square is visible then it's denoted with ' | ' (ASCII value 124) character. The board contains no other character than ', ' | ' and of course ' (ASCII Value 32). The border lines of the squares can only be along the grid lines. Each board lines end with a ' # ' (Hash character) which denotes the end of line. This character isn't a part of the grid or square. The last test case was followed by a single zero, which should wasn't be processed.
Output
For each test case, print the case number and ' Yes ' or ' No ', depending on whether it's possible to form the target.
Sample Input
Sample ouput
Case 1:yes
Case 2:yes
Case 3:no
Case 4:yes
Solution: Feel the recent problems are very test code ability (but I am very water), think of only nine kinds of layout after the thinking of the problem is basically over, all the selection scheme only 2^9, direct binary enumeration, for the same selection scheme, different placement order will also bring different coverage results, The solution is next_permutation (), pre-processing the different small squares of the overlay lattice label, the next violence is good.
1#include <bits/stdc++.h>2 3 using namespacestd;4 5 Const intMAXN = (1<<9);6 Const intN =5, M =9;7 Const intKind =9;8 9 intedge[9][8] = {{1,3,9, -, -, +, +, A}};Ten intcore[9][4] = {{Ten, One, A, -}}; One intBits[kind+1],target[n*M]; A - intRead () { - Charstr[ -]; the intCNT =0, edges =0; - for(inti =0; I < n;i++){ - gets (str); - if(str[0] =='0')return-1; + for(intj =0; J < m;j++){ - if(Str[j] = =' ') target[cnt++] =0; + Elsetarget[cnt++] =1, edges++; A } at } - returnedges; - } - - voidinit () { - for(inti =0; I <3; i++){ in for(intj =0; J <3; j + +){ - if(!i &&!j)Continue; to intPlus,minus; + if(J = =0) plus =9, minus =3; - ElsePlus =2, minus =1; the for(intK =0; k <8; k++){ *edge[i*3+j][k] = edge[i*3+j-minus][k]+Plus; $ }Panax Notoginseng for(intK =0; k <4; k++){ -core[i*3+j][k] = core[i*3+j-minus][k]+Plus; the } + } A } the } + - intBitcount (ints) { $ returns = =0?0: Bitcount (s>>1) + (s&1); $ } - - voidBitpos (ints) { the intCNT =0; - for(inti =0; I <9; i++){Wuyi if(s& (1<<i)) bits[cnt++] =i; the } - } Wu - intIcase =1; About $ intMain () - { - #ifdef Geh -Freopen ("HELLOWORLD.01,INP","R", stdin); A #endif + init (); the intedge_cnt; - while(edge_cnt=Read ()) { $ if(edge_cnt = =-1) Break; the inttmp[m*N]; the BOOLOK =false; the for(ints =0; s < maxn;s++){ the intn =Bitcount (s); - Bitpos (s); in if(n>6|| N8<EDGE_CNT)Continue; the Do{ thememset (TMP,0,sizeof(TMP)); About for(inti =0; I < n;i++){ the for(intj =0; J <8; j + +){ theTMP[EDGE[BITS[I]][J]] =1; the } + for(intj =0; J <4; j + +){ -TMP[CORE[BITS[I]][J]] =0; the }Bayi } the the if(MEMCMP (Tmp,target,sizeof(target)) ==0){ -OK =true; - Break; the } the} while(Next_permutation (bits,bits+n)); the if(OK) Break; the } -printf"Case %d:", icase++); the if(OK) printf ("yes\n"); the Elseprintf"no\n"); the }94 return 0; the}
Uva12113-overlapping squares (Binary enumeration)