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 1and 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
题目大意 :题目中给出了几幅图,判断给出的矩阵能否有题目中的图片叠加而成。
题解:该题难在构图与题意上。如果能够由每个图片叠加而成那么一定会有个先后。也就是说,一定能用拓扑排序将其排列好。如果拓扑排序没有成功排出,输出 THESE WINDOWS ARE BROKEN。否则输出THESE WINDOWS ARE CLEAN
还有一个难点就是在构图上。我们只需要记录每个数字的左上角的坐标,然后进行搜索见图,即判断该数字本身位置有没有被覆盖,右边下边以及右下角有没有被覆盖。被覆盖的话,就用邻接矩阵标记为1.并记录节点的 入度
//判断所有位置的覆盖情况 //如果a覆盖b 则构造一条边edge[b][a]=1 最后得到一个图 //这个图一定是无环的 如果有环则表示a覆盖b b又覆盖a //即显示不正常 #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<queue> #include<vector> using namespace std; const int N=1E5+7; int arr[5][5]; int arr2[10][2]={{0,0}, {1,1},{1,2},{1,3}, {2,1},{2,2},{2,3}, {3,1},{3,2},{3,3} };// 每个区域的左上角 int dir[4][2]={{0,0},{0,1},{1,0},{1,1}};//对应四个方向 本身,右边,下边,还有右下角 int map[20][20]; int in[N]; int main(){ string a; while(cin>>a&&a!="ENDOFINPUT"){ memset(in,0,sizeof(in)); memset(arr,0,sizeof(arr)); memset(map,0,sizeof(map)); for(int i=1;i<=4;i++) for(int j=1;j<=4;j++){ scanf("%d",&arr[i][j]); } string b; cin>>b; //建图 for(int i=1;i<=9;i++){ for(int j=0;j<4;j++){ int dx=arr2[i][0]+dir[j][0]; int dy=arr2[i][1]+dir[j][1]; int dz=arr[dx][dy]; if(dz!=i&&map[dz][i]==0){ map[dz][i]=1; in[i]++; } } } queue<int >que; for(int i=1;i<=9;i++){ if(in[i]==0){ que.push(i); } } int sum=0; while(que.size()){ int xx=que.front(); que.pop(); sum++; for(int i=1;i<=9;i++){ if(map[xx][i]==1){ in[i]--; if(in[i]==0){ que.push(i); } } } } if(sum==9) puts("THESE WINDOWS ARE CLEAN"); else puts("THESE WINDOWS ARE BROKEN"); } return 0; }