Topic Links:ah haha, dot me dot Me
Test Instructions:
A quick screen in many areas, the area can be covered with each other, to cover the place belongs to the full coverage. Give the final position of the screen to see if the screen is right or wrong.
Ideas:
Topological sequencing, this simplification point, that is, like Chu Chu,, the points of the clear, either this piece of land is mine, or this piece of land is yours, not pure in one person to do the situation, so if there is a sort of ring, then say this fast screen is bad ... There is one more detail to note is that the number I is in the first row of the first few columns, so this to find the law, and then enumerate it all OK.
Title:Window pains
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 1588 |
|
Accepted: 792 |
Description
Boudreaux likes to multitask, especially if it comes to using his computer. Never satisfied with just running one application at a time, he usually runs nine applications, and each of its own window. Due to limited screen real estate, he overlaps these windows and brings whatever window he currently needs The foreground. If his screens were a 4 x 4 grid of squares, each of Boudreaux's windows would be represented by the following 2 x 2 window S
1 |
1 |
|
. |
1 |
1 |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
|
. |
2 |
2 |
. |
. |
2 |
2 |
. |
. |
. |
. |
. |
. |
. |
. |
. |
|
. |
. |
3 |
3 |
. |
. |
3 |
3 |
. |
. |
. |
. |
. |
. |
. |
. |
|
. |
. |
. |
. |
4 |
4 |
. |
. |
4 |
4 |
. |
. |
. |
. |
. |
. |
|
. |
. |
. |
. |
. |
5 |
5 |
. |
. |
5 |
5 |
. |
. |
. |
. |
. |
|
. |
. |
. |
. |
. |
. |
6 |
6 |
. |
. |
6 |
6 |
. |
. |
. |
. |
|
. |
. |
. |
. |
. |
. |
. |
. |
7 |
7 |
. |
. |
7 |
7 |
. |
. |
|
. |
. |
. |
. |
. |
. |
. |
. |
. |
8 |
8 |
. |
. |
8 |
8 |
. |
|
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
9 |
9 |
. |
. |
9 |
9 |
|
When Boudreaux brings a window to the foreground, all of its squares come to the top, overlapping any squares it shares WI th other windows. For example, if window1
and thenWindow2were brought to the foreground, the resulting representation would is:
1 |
2 |
2 |
? |
1 |
2 |
2 |
? |
? |
? |
? |
? |
? |
? |
? |
? |
|
If window 4 were then brought to the foreground: |
1 |
2 |
2 |
? |
4 |
4 |
2 |
? |
4 |
4 |
? |
? |
? |
? |
? |
? |
|
... 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 O CCur If windows were being brought to the foreground correctly. And this is where you are come in ...
Input
Input to this problem would consist of a (Non-empty) series of up to data sets. Each data set is formatted according to the following description, and there would be no blank lines separating data s Ets.
A Single Data set have 3 components:
- Start line-a Single line:
START
- Screen Shot-four lines this represent the current graphical representation of the windows in Boudreaux ' s screen. Each position in this 4 x 4 matrix would represent the current piece of Windows showing in each square. To do input easier, the list of numbers on each line would be delimited by a single space.
- End line-a Single line:
END
After the last data set, there'll is a single line:
Endofinput
Note that each piece of visible window would appear only in screen areas where the window is could appear when brought to the Front. For instance, a 1 can is only appear in the top left quadrant.
Output
For each data set, there'll is exactly one line of output. If there exists a sequence of bringing windows to the foreground so would result in the graphical representation of the Windows on Boudreaux ' s screen, the output would be a single line with the statement:
These WINDOWS is clean
Otherwise, the output would be a single line with the statement:
These WINDOWS is broken
Sample Input
START1 2 3 5 6 (8 9) 8 9 9endstart1 1 3 1 3 PNS 7 9 $7 9 9ENDENDOFINPUT
Sample Output
These windows is Cleanthese windows is broken
Source
South Central USA 2003
The code is:
#include <cstdio> #include <iostream> #include <vector> #include <cstring> #include <queue > #include <algorithm>using namespace std;const int Maxn=5+10;int map[maxn][maxn],in[maxn];queue<int>q ; Vector<int>vec[maxn];int dx[]={0,0,1,1};int Dy[]={0,1,0,1};int topo () {int sum=9; while (! Q.empty ()) Q.pop (); for (int i=1;i<=9;i++) {if (in[i]==0) Q.push (i); } while (! Q.empty ()) {int Temp=q.front (); Q.pop (); sum--; for (int i=0;i<vec[temp].size (); i++) {if (--in[vec[temp][i]]==0) Q.push (Vec[temp][i]); }} if (sum>0) return 0; else return 1;} void Init () {char str[10]; for (int i=1;i<=9;i++) {vec[i].clear (); in[i]=0; } for (int i=1;i<=9;i++) {int x= (i-1)/3+1; int y=i%3==0?3:i%3; for (int j=0;j<=3;j++) {int tx=x+dx[j]; int TY=Y+DY[J];if (map[tx][ty]!=i) {vec[i].push_back (map[tx][ty]); in[map[tx][ty]]++; }}} scanf ("%s", str);} void Solve () {int Ans=topo (); if (ans) cout<< "These WINDOWS is clean" <<endl; Else cout<< "These WINDOWS is broken" <<ENDL;} int main () {char str[10]; while (~SCANF ("%s", str)) {if (strcmp (str, "Endofinput") ==0) return 0; for (int i=1;i<=4;i++) for (int j=1;j<=4;j++) scanf ("%d", &map[i][j]); Init (); Solve (); } return 0;}