Treats a square as an edge between connected characters. For example, there is a a+,b-on a square, from a A to a B + edge, indicating that the character can be transformed by this square.
If you can make a ring, you can be infinitely big ... A sentence to write a topology or something ...
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 #definell Long Long6 #defineull unsigned long Long7 #defineD Double8 using namespacestd;9 BOOLmp[ -][ -];Ten intdl[233],rd[233];; One intI,j,k,n,m,l,r; A Chars[ at]; - - intRA,FH;CharRx; theInlineintRead () { -Rx=getchar (), ra=0, fh=1; - while((rx<'0'|| Rx>'9') &&rx!='-') rx=GetChar (); - if(rx=='-') fh=-1, rx=GetChar (); + while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnTalfh; - } + intMain () { AN=read ();inta[5]; at for(i=1; i<=n;i++){ -scanf"%s", s+1); - for(j=1; j<=4; j + +)if(s[j<<1]!='0') -A[j]= (s[j*2-1]-'A'+1)*2+ (s[j<<1]=='-');Elsea[j]=-233; - //for (j=1;j<=4;j++) printf ("%d", A[j]);p UTS (""); - for(j=1;j<4; j + +)if(a[j]>0) for(k=j+1; k<=4; k++)if(a[k]>0) in //printf ("%d-->%d\n%d-->%d\n", A[j]^1,a[k],a[k]^1,a[j]), -mp[a[j]^1][a[k]]=mp[a[k]^1][a[j]]=1; to //printf ("(%d)", i); + } - for(i=2; i<= -; i++){ the for(j=2; j<= -; j + +)if(Mp[j][i]) rd[i]++; * if(!rd[i]) dl[++r]=i; $ }Panax Notoginseng while(l<R) - for(intNow=dl[++l],i=2; i<= -; i++)if(mp[now][i]&&!--Rd[i]) thedl[++r]=i; + if(r== the) puts ("bounded");ElsePuts"unbounded"); A}View Code
[bzoj3953] [WF2013] self-assembly