Window Pains
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2027 | Accepted: 1025 |
Description
Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one application at a time, he usually runs nine applications, each in its own window. Due to limited screen real estate, he overlaps these windows and brings whatever window he currently needs to work with to the foreground. If his screen were a 4 x 4 grid of squares, each of Boudreaux's windows would be represented by the following 2 x 2 windows:
When Boudreaux brings a window to the foreground, all of its squares come to the top, overlapping any squares it shares with other windows. For example, if window
1
and then window
2 were brought to the foreground, the resulting representation would be:
. . . and so on . . .
Unfortunately, Boudreaux's computer is very unreliable and crashes often. He could easily tell if a crash occurred by looking at the windows and seeing a graphical representation that should not occur if windows were being brought to the foreground correctly. And this is where you come in . . .
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
| If window 4 were then brought to the foreground: |
|
Unfortunately, Boudreaux's computer is very unreliable and crashes often. He could easily tell if a crash occurred by looking at the windows and seeing a graphical representation that should not occur if windows were being brought to the foreground correctly. And this is where you come in . . .
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 3 components:
After the last data set, there will be a single line:
ENDOFINPUT
Note that each piece of visible window will appear only in screen areas where the window could appear when brought to the front. For instance, a 1 can only appear in the top left quadrant.
A single data set has 3 components:
- Start line - A single line:
START - Screen Shot - Four lines that represent the current graphical representation of the windows on Boudreaux's screen. Each position in this 4 x 4 matrix will represent the current piece of window showing in each square. To make input easier, the list of numbers on each line will be delimited by a single space.
- End line - A single line:
END
After the last data set, there will be a single line:
ENDOFINPUT
Note that each piece of visible window will appear only in screen areas where the window could appear when brought to the front. For instance, a 1 can only appear in the top left quadrant.
Output
For each data set, there will be exactly one line of output. If there exists a sequence of bringing windows to the foreground that would result in the graphical representation of the windows on Boudreaux's screen, the output will be a single line with the statement:
THESE WINDOWS ARE CLEAN
Otherwise, the output will be a single line with the statement:
THESE WINDOWS ARE BROKEN
THESE WINDOWS ARE CLEAN
Otherwise, the output will be a single line with the statement:
THESE WINDOWS ARE BROKEN
Sample Input
START 1 2 3 3 4 5 6 6 7 8 9 9 7 8 9 9 END START 1 1 3 3 4 1 3 3 7 7 9 9 7 7 9 9 END ENDOFINPUT
Sample Output
THESE WINDOWS ARE CLEAN THESE WINDOWS ARE BROKEN
Source
——————————————————我是分割线——————————————————
拓扑排序,绝世好题。
前5分钟只想出来暴搜方法
后来想到可以记录每个方格能被哪些窗口盖住
转化成图论问题,拓扑排序求环
有环就是死机,否则就是好的。
真是的,如果不是事先知道这题是拓扑排序,我就只会写一发搜索剪枝去骗分了.......
读入写错了,调了半个钟头。
1 /* 2 Problem:poj 2585 3 OJ: POJ 4 User: S.B.S. 5 Time: 0 ms 6 Memory: 700 kb 7 Length: 1991 b 8 */ 9 #include<iostream> 10 #include<cstdio> 11 #include<cstring> 12 #include<cmath> 13 #include<algorithm> 14 #include<queue> 15 #include<cstdlib> 16 #include<iomanip> 17 #include<cassert> 18 #include<climits> 19 #include<vector> 20 #include<list> 21 #include<map> 22 #define maxn 10001 23 #define F(i,j,k) for(int i=j;i<k;i++) 24 #define M(a,b) memset(a,b,sizeof(a)) 25 #define FF(i,j,k) for(int i=j;i>=k;i--) 26 #define inf 0x7fffffff 27 #define maxm 2016 28 #define mod 1000000007 29 //#define LOCAL 30 using namespace std; 31 int read(){ 32 int x=0,f=1;char ch=getchar(); 33 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 34 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 35 return x*f; 36 } 37 int n,m; 38 int sc[4][4]; 39 string cr[4][4]; 40 bool vis[10]; 41 int in[10]; 42 bool g[10][10]; 43 int t; 44 string s; 45 inline void init() 46 { 47 F(i,0,4)F(j,0,4) cr[i][j].erase(); 48 F(k,1,10){ 49 int i=(k-1)/3; 50 int j=(k-1)%3; 51 cr[i][j]+=char(k+'0'); 52 cr[i][j+1]+=char(k+'0'); 53 cr[i+1][j]+=char(k+'0'); 54 cr[i+1][j+1]+=char(k+'0'); 55 } 56 } 57 inline void input() 58 { 59 int i,j; 60 M(vis,0);M(in,0);M(g,0); 61 t=0; 62 int k; 63 F(i,0,4)F(j,0,4){ 64 cin>>k; 65 sc[i][j]=k; 66 if(!vis[k]) t++; 67 vis[k]=true; 68 } 69 } 70 inline void build() 71 { 72 int a,b; 73 F(i,0,4)F(j,0,4)F(k,0,cr[i][j].length()) 74 { 75 if((!g[sc[i][j]][cr[i][j][k]-'0'])&&(sc[i][j]!=cr[i][j][k]-'0')) 76 { 77 g[sc[i][j]][cr[i][j][k]-'0']=true; 78 in[cr[i][j][k]-'0']++; 79 } 80 } 81 } 82 inline bool ok() 83 { 84 int i,j,k; 85 F(k,0,t){ 86 i=1; 87 while(!vis[i]||(i<=9&&in[i]>0)) i++; 88 if(i>9) return false; 89 vis[i]=false; 90 F(j,1,10){ 91 if(vis[j]&&g[i][j]) in[j]--; 92 } 93 } 94 return true; 95 } 96 int main() 97 { 98 std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y; 99 #ifdef LOCAL 100 freopen("data.in","r",stdin); 101 freopen("data.out","w",stdout); 102 #endif 103 init(); 104 while(cin>>s) 105 { 106 if(s=="ENDOFINPUT") break; 107 input(); 108 build(); 109 if(ok()) cout<<"THESE WINDOWS ARE CLEAN"<<endl; 110 else cout<<"THESE WINDOWS ARE BROKEN"<<endl; 111 cin>>s; 112 } 113 return 0; 114 }