Time Limit: 1000MS | Memory Limit: 65536K |
Description
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
| 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
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
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
————————————————————集训7.2的分割线————————————————————
前言:集训已经一个星期整了。只剩下四分之三。进度还是这么可怜。看看Roll和瓜神,一天8、9题。我却一天两题,唉。抓紧每一分钟吧!
思路:明显是拓扑排序,但是建图需要仔细思考。一定要注意题意!题目说窗口K一定只能存在于自己的区域内,是不能拖动的。所以每个点上可能出现的数字是一定的。假如某一点出现了一个数字,那么它一定覆盖了其他被覆盖的数字上面,这就意味着存在一条有向边(拓扑层数:K < k1, K < k2, ......K < kn)。
开一个vector,对9个数字打表,每个数字应该有4个点。技巧::以数字为变量,Hash一下,变成3×3的图,这样就可以cover[ i+d[ ][0] ][ j+d[ ][1] ].push_back()了。调用cover[i][j].size()就可以知道该点可能出现数字的个数。建图的时候,千万要注意重边的现象!
然后拓扑排序,一顿套模板。
代码如下:
/*
ID: j.sure.1
PROG:
LANG: C++
*/
/****************************************/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <iostream>
using namespace std;
/****************************************/
const int N = 10;
const int d[][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
char str[15];
char S[] = {"ENDOFINPUT"};
bool G[N][N];
int indeg[N], ans;
vector <int> cover[4][4];
queue <int> q;
void init()
{
ans = 0;
memset(G, 0, sizeof(G));
memset(indeg, 0, sizeof(indeg));
while(!q.empty()) q.pop();
}
void Topsort()
{
for(int i = 1; i < N; i++) {
if(indeg[i] == 0) {
q.push(i);
}
}
while(!q.empty()) {
int cur = q.front();
q.pop();
ans++;
for(int j = 1; j < N; j++) if(G[cur][j]) {
indeg[j]--;
if(!indeg[j]) q.push(j);
}
}
if(ans == 9)
puts("THESE WINDOWS ARE CLEAN");
else
puts("THESE WINDOWS ARE BROKEN");
}
int main()
{
#ifdef J_Sure
freopen("2585.in", "r", stdin);
// freopen(".out", "w", stdout);
#endif
for(int k = 1; k < N; k++) {
for(int dd = 0; dd < 4; dd++) {
int i = (k-1)/3 + d[dd][0], j = (k-1)%3 + d[dd][1];
cover[i][j].push_back(k);
}
}
while(scanf("%s", str)) {
if(strcmp(str, S) == 0) break;
init();
int num;
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
scanf("%d", &num);
for(int k = 0; k < cover[i][j].size(); k++) {
int &to = cover[i][j][k];
if(to != num && !G[num][to]) {
G[num][to] = true;
indeg[to]++;
}
}
}
}
scanf("%s", str);
Topsort();
}
return 0;
}