POJ 2585 window pains (topology sort • Windows overlay)

Source: Internet
Author: User

Test instructions has a 4*4 monitor with 9 programs per program that occupies 2*2 grid their location when you run a program This program will show up in the top layer covering other programs to give you a moment of the monitor's judgment at this time the computer freezes (there is an illegal cover relationship)

The key to the application of topological sequencing is to build the diagram when there is another program B in the area of a program A, which indicates that a is running before B, so we can build a a<b topological relationship and finally decide if there's a ring on the line. I think the subscript for 0 is easier to operate, so it's also for 0.

#include <cstdio> #include <cstring> #include <vector>using namespace std;const int N = 10;int G[n][n], I    N[n], q[n];vector<int> e[n];void build ()//Map {memset (in, 0, sizeof (in));        for (int k = 0; k < 9; ++k) {e[k].clear (); int i = K/3, j = k% 3, t;  Gets the upper-left coordinate of the program k for (int x = 0, x < 2; ++x) for (int y = 0; y < 2; ++y) {t = g[i + x][j            + y];                if (t! = k)//program K run K < T {E[k].push_back (T) before program T;            ++IN[T];    }}}}bool Topo () {build ();    int front = 0, rear = 0, cur;    for (int i = 0; i < 9; ++i) if (!in[i]) q[rear++] = i;        while (front < rear) {cur = q[front++];            for (int i = 0; i < e[cur].size (); ++i) {int j = e[cur][i]; if (! (        --IN[J])) q[rear++] = j; }} return front >= 9;    Front < 9 o'clock with Ring}int main () {char s[100]; while (scanf ("%s", s), s[0]! = 'E ') {for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) scanf ("%d", &g[i        ][J]),--g[i][j];        scanf ("%s", s);        printf ("These WINDOWS is"); Puts (topo ()?    "Clean": "broken"); } return 0;}

Window pains

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:
    1. Start line-a Single line:
      START

    2. 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.
    3. 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


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2585 window pains (topology sort • Windows overlay)

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.