POJ-2585 Window Pains
来源:互联网 发布:淘宝店卖家页面图片 编辑:程序博客网 时间:2024/04/30 14:46
Window Pains
Time Limit: 1000MS Memory Limit: 65536K
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 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:
11..11...........22..22...........33..33............44..44...........55..55...........66..66............77..77...........88..88...........99..99When 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 window1and then window2 were brought to the foreground, the resulting representation would be:122?122?????????If window 4 were then brought to the foreground:122?442?44??????. . . 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 . . .
11..11...........22..22...........33..33............44..44...........55..55...........66..66............77..77...........88..88...........99..99When 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 window1and then window2 were brought to the foreground, the resulting representation would be:122?122?????????If window 4 were then brought to the foreground:122?442?44??????. . . 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 . . .
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
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
————————————————————集训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.1PROG: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");elseputs("THESE WINDOWS ARE BROKEN");}int main(){#ifdef J_Surefreopen("2585.in", "r", stdin);//freopen(".out", "w", stdout);#endiffor(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;}
0 0
- poj 2585 Window Pains
- POJ-2585 Window Pains
- poj 2585 Window Pains
- POJ-2585 Window Pains
- POJ 2585Window Pains
- 【POJ】[2585]Window Pains
- Window Pains POJ 2585
- POJ 2585 Window Pains【拓扑】
- POJ 2585 Window Pains 拓扑排序
- POJ 2585 | ZOJ 2193 Window Pains
- poj 2585 Window Pains (有向环)
- POJ 2585 Window Pains (拓扑排序)
- POJ:2585 Window Pains(拓扑排序)
- poj 2585 Window Pains zoj 2193
- [POJ 2585] Window Pains (拓扑排序)
- POJ 2585 Window Pains(拓扑排序判定)
- poj 2585 Window Pains 拓扑排序
- POJ 2585 zoj 2193 Window Pains
- 删除数据库重复数据
- 如何只备份一张表的数据
- 4个禁忌让你折寿20岁
- Html.ActionLink详解
- CSS 属性设置优先级问题
- POJ-2585 Window Pains
- XML中的转义字符
- 使用WebClient从FTP服务器下载文件…
- 使用SharePoint 2010 客…
- window.dialogArguments
- ASP.NET 4.0的ClientIDMode属…
- reuqest获取服务器一些信息方法集合 java
- 序列化成json数据
- C# DateTime 日期加1天&…