POJ2585 Window Pains,

Source: Internet
Author: User

POJ2585 Window Pains,

Window Pains

Time Limit:1000 MS   Memory Limit:65536 K
Total Submissions:1843   Accepted:919

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 the foreground. if his screen were a 4x4 grid of squares, each of Boudreaux's windows wocould be represented by the following 2x2 windows:
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 with other windows. For example, if window 1 And thenWindow 2Were brought to the foreground, the resulting representation wocould be:
1 2 2 ?
1 2 2 ?
? ? ? ?
? ? ? ?
If window4Were 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 cocould easily tell if a crash occurred by looking at the windows and seeing a graphical representation that shocould 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 cocould 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 wocould 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

Sample Input

START1 2 3 34 5 6 67 8 9 97 8 9 9ENDSTART1 1 3 34 1 3 37 7 9 97 7 9 9ENDENDOFINPUT

Sample Output

THESE WINDOWS ARE CLEANTHESE WINDOWS ARE BROKEN

Question link: http://poj.org/problem? Id = 2585

Question:
There is a display screen with a 4x4 mesh, and there are 9 2x2 Program windows. When a window is adjusted to the front, all the numbers in its squares are located in the front, overwrite the common square. The window is adjusted to the very beginning in different order, but the computer is unstable and often crashes. The status of the input window to determine whether such window status can appear. If yes, the computer does not crash and "these windows are clean" is output; otherwise, "these windows are broken" is output ".
Each group of data has started with "START" and ended with "END. The Center shows the status of the square number. If "ENDOFINPUT" is input, the input ends.

Number in each square of a computer:
1 1, 2, 2, 3, 3
1, 4 1, 2, 4, 5 2, 3, 5, 6 3, 6
4 4, 5 5, 6, 8, 9 6, 9
7 7, 8 8, 9 9

 

 

 

 

 

The numbers displayed in the corresponding square cover the other numbers in the corresponding square. Establish an edge between overwrites to check whether the final graph is normal.

This is a topological sorting problem. In the figure, there cannot be loops. If there is a ring, it is unreasonable, that is, the computer crashes. The no-ring diagram is reasonable.

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 using namespace std; 5 int L [10] [10]; 6 int indegree [10]; 7 int TopSort (); 8 int main () 9 {10 int I, j, t; 11 string cover [5] [5]; 12 for (I = 0; I <3; I ++) 13 {14 for (j = 0; j <3; j ++) 15 {16 cover [I] [j] + = j + 1 + I * 3 + '0 '; 17 cover [I] [j + 1] + = j + 1 + I * 3 + '0 '; 18 cover [I + 1] [j] + = j + 1 + I * 3 + '0 '; 19 cover [I + 1] [j + 1] + = j + 1 + I * 3 + '0 '; 20} 21} 22/** 23 for (I = 0; I <4; I ++) 24 {25 for (j = 0; j <4; j ++) 26 {27 string: iterator y; 28 for (y = cover [I] [j]. begin (); y! = Cover [I] [j]. end (); ++ y) 29 {30 cout <* y; 31} 32 cout <"; 33} 34 cout <endl; 35} 36 */37 string s; 38 while (cin> s) 39 {40 getchar (); 41 if (s = "ENDOFINPUT") break; 42 memset (indegree, 0, sizeof (indegree); 43 memset (L, 0, sizeof (L); 44 for (I = 0; I <4; I ++) 45 {46 for (j = 0; j <4; j ++) 47 {48 char x; 49 scanf ("% c", & x ); 50 string: iterator y; 51 for (y = cover [I] [j]. begin (); y! = Cover [I] [j]. end (); ++ y) 52 {53 if (* y )! = X & L [x-'0'] [(* y)-'0'] = 0) 54 {55 L [x-'0'] [(* y)-'0'] = 1; 56 indegree [(* y)-'0'] ++; 57} 58} 59 getchar (); 60} 61} 62 cin> s; 63 getchar (); 64/** 65 for (I = 1; I <10; I ++) 66 {67 cout <I <":"; 68 for (j = 0; j <10; j ++) 69 {70 if (L [I] [j] = 1) 71 cout <j <"; 72} 73 cout <endl; 74} 75 cout <"indegree:"; 76 for (I = 1; I <10; I ++) cout <indegree [I] <""; 77 cout <endl; 78 */79 int flag = TopSort (); 80 if (flag) cout <"these windows are clean" <endl; 81 else cout <"these windows are broken" <endl; 82} 83 return 0; 84} 85 int TopSort () 86 {87 int I, j; 88 int n = 9; 89 int sign = 0; 90 while (n --) 91 {92 sign = 0; 93 for (I = 1; I <10; I ++) 94 {95 if (indegree [I] = 0) sign = I; 96} 97 if (sign> 0) 98 {99 for (j = 0; j <10; j ++) 100 {101 if (L [sign] [j]) 102 indegree [j] --; 103} 104 indegree [sign] =-1; 105} 106 else if (sign = 0) return 0; 107} 108 return 1; 109}View Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.