1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineCL (b) memset (A,b,sizeof (a))5 using namespacestd;6 7 Const intmaxn=Ten;8 9 intT;Ten intCNT[MAXN]; One intMP[MAXN][MAXN]; A intNUM[MAXN][MAXN]; - intCOVER[MAXN][MAXN][MAXN]; - BOOLVIS[MAXN]; the BOOLLINK[MAXN][MAXN]; - - intdx[]= {0,0,1,1}; - intdy[]= {0,1,0,1}; + - voidInit () + { A inti,j; atCL (cover,0); - for(intk=0; k<9; k++) - { -i=k/3, j=k%3; - for(intL=0; l<4; l++) - { in intx=i+Dx[l]; - inty=j+Dy[l]; tocover[x][y][num[x][y]++]=k+1; + } - } the } * $ voidbuild ()Panax Notoginseng { - for(intI=0; i<4; i++) the { + for(intj=0; j<4; J + +) A { the for(intk=0; k<num[i][j]; k++) + { - if((!Link[mp[i][j]][cover[i][j][k]]) $&& (mp[i][j]!=Cover[i][j][k])) $ { -link[mp[i][j]][cover[i][j][k]]=true; -cnt[cover[i][j][k]]++; the } - }Wuyi } the } - } Wu - BOOLTopsort () About { $ while(t--) - { - - intnow=1; A while(!vis[now]| | (now<=9&&cnt[now]>0)) + { thenow++; - //printf ("%d\n", now); $ } the the if(now>9) the { the return false; - } invis[now]=false; the for(intI=1; i<=9; i++) the { About if(vis[i]&&Link[now][i]) the { thecnt[i]--; the } + } - } the return true;Bayi } the the intMain () - { - init (); the CharSTR[MAXN]; the while(SCANF ("%s", str) &&str[0]=='S') the { theCL (CNT,0), t=0; -CL (VIS,false); theCL (link,false); the for(intI=0; i<4; i++) the {94 for(intj=0; j<4; J + +) the { thescanf"%d",&mp[i][j]); the if(!Vis[mp[i][j]])98 { Aboutt++; -vis[mp[i][j]]=true;101 }102 }103 }104 build (); thescanf"%s", str);106 if(Topsort ()) puts ("these WINDOWS is clean");107 ElsePuts"These WINDOWS is broken");108 }109 return 0; the}/*111 the START113 1 2 3 3 the 4 5 6 6 the 7 8 9 9 the 7 8 9 9117 END118 START119 1 1 3 3 - 4 1 3 3121 7 7 9 9122 7 7 9 9123 END124 Endofinput the 126 */
POJ 2585 Window pains topology Ordering