Window Pains

Time Limit: 1000MS   Memory Limit: 65536K
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 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:

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 1and then window 2 were brought to the foreground, the resulting representation would be:

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 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: 

  1. Start line - A single line: 
    START
  2. 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.
  3. 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

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 题目链接:http://poj.org/problem?id=2585



题意:
有一个拥有4×4网格的显示屏,有9个2×2的程序窗口,把一个窗口调到最前时,它的所有方格中的数字都位于最前,覆盖共用的方格。按照不同的顺序将窗口调到最前,但是计算机很不稳定,经常崩溃。输入的窗口的状态,判断是否能出现这样的窗口状态。可以的话说明计算机没有崩溃,输出“THESE WINDOWS ARE CLEAN”,否则输出“THESE WINDOWS ARE BROKEN”。
每组数据已“START”开始,已“END”结束。中间是方格数字显现的状态。如果输入“ENDOFINPUT”就结束输入。
计算机每个方格中拥有的数字:
 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

那么相应方格中显示出来的数字就覆盖了相应方格中那些其他的数字。覆盖之间建立一条边,最终形成的图是否正常。

这就是一个拓扑排序问题,图中不能有环,有环说明不合理,也就是计算机崩溃。无环说明图合理。

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int L[][];
int indegree[];
int TopSort();
int main()
{
int i,j,t;
string cover[][];
for(i=; i<; i++)
{
for(j=; j<; j++)
{
cover[i][j]+=j++i*+'';
cover[i][j+]+=j++i*+'';
cover[i+][j]+=j++i*+'';
cover[i+][j+]+=j++i*+'';
}
}
/**
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
string::iterator y;
for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y)
{
cout<<*y;
}
cout<<" ";
}
cout<<endl;
}
*/
string s;
while(cin>>s)
{
getchar();
if(s=="ENDOFINPUT") break;
memset(indegree,,sizeof(indegree));
memset(L,,sizeof(L));
for(i=; i<; i++)
{
for(j=; j<; j++)
{
char x;
scanf("%c",&x);
string::iterator y;
for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y)
{
if((*y)!=x&&L[x-''][(*y)-'']==)
{
L[x-''][(*y)-'']=;
indegree[(*y)-'']++;
}
}
getchar();
}
}
cin>>s;
getchar();
/**
for(i=1; i<10; i++)
{
cout<<i<<":";
for(j=0; j<10; j++)
{
if(L[i][j]==1)
cout<<j<<" ";
}
cout<<endl;
}
cout<<"indegree:";
for(i=1; i<10; i++) cout<<indegree[i]<<" ";
cout<<endl;
*/
int flag=TopSort();
if(flag) cout<<"THESE WINDOWS ARE CLEAN"<<endl;
else cout<<"THESE WINDOWS ARE BROKEN"<<endl;
}
return ;
}
int TopSort()
{
int i,j;
int n=;
int sign=;
while(n--)
{
sign=;
for(i=; i<; i++)
{
if(indegree[i]==) sign=i;
}
if(sign>)
{
for(j=; j<; j++)
{
if(L[sign][j])
indegree[j]--;
}
indegree[sign]=-;
}
else if(sign==) return ;
}
return ;
}

POJ2585 Window Pains 拓扑排序的更多相关文章

  1. [poj2585]Window Pains_拓扑排序

    Window Pains poj-2585 题目大意:给出一个4*4的方格表,由9种数字组成.其中,每一种数字只会出现在特定的位置,后出现的数字会覆盖之前在当前方格表内出现的.询问当前给出的方格表是否 ...

  2. POJ 2585.Window Pains 拓扑排序

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1888   Accepted: 944 Descr ...

  3. 【POJ 2585】Window Pains 拓扑排序

    Description . . . and so on . . . Unfortunately, Boudreaux's computer is very unreliable and crashes ...

  4. POJ 2585:Window Pains(拓扑排序)

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2524   Accepted: 1284 Desc ...

  5. pojWindow Pains(拓扑排序)

    题目链接: 啊哈哈,点我点我 题意: 一快屏幕分非常多区域,区域之间能够相互覆盖,要覆盖就把属于自己的地方所有覆盖. 给出这块屏幕终于的位置.看这块屏幕是对的还是错的.. 思路: 拓扑排序,这个简化点 ...

  6. [POJ 2585] Window Pains 拓朴排序

    题意:你现在有9个2*2的窗口在4*4的屏幕上面,由于这9这小窗口叠放顺序不固定,所以在4*4屏幕上有些窗口只会露出来一部分. 如果电脑坏了的话,那么那个屏幕上的各小窗口叠放会出现错误.你的任务就是判 ...

  7. ACM/ICPC 之 拓扑排序范例(POJ1094-POJ2585)

    两道拓扑排序问题的范例,用拓扑排序解决的实质是一个单向关系问题 POJ1094(ZOJ1060)-Sortng It All Out 题意简单,但需要考虑的地方很多,因此很容易将code写繁琐了,会给 ...

  8. poj 2585 Window Pains 解题报告

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2027   Accepted: 1025 Desc ...

  9. [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果

    [C#]使用 C# 代码实现拓扑排序   目录 0.参考资料 1.介绍 2.原理 3.实现 4.深度优先搜索实现 回到顶部 0.参考资料 尊重他人的劳动成果,贴上参考的资料地址,本文仅作学习记录之用. ...

随机推荐

  1. html大小写问题

    js中变量名,函数,关键字都区分大小写,如var i;和var I;是两个不同的变量. css中定义的元素名称不区分大小写的. html中,标签和标签属性统一使用小写形式,固有属性也一律使用小写,自定 ...

  2. jquery函数写法

    普通jquery函数写法 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script&g ...

  3. 位运算骚操作 Part 1

    ▶ 原文标题<Bit Twiddling Hacks>,地址:https://graphics.stanford.edu/~seander/bithacks.html ▶ 额外参考资料:h ...

  4. Zabbix监控系统端口

    参考网站: https://www.cnblogs.com/nulige/p/7072019.html

  5. CENTOS 挂载ntfs移动硬盘

    参考网址: http://www.it610.com/article/3368930.htm (较全)http://blog.51cto.com/ultrasql/1927672

  6. docker使用笔记1

    rhel6安装 yum -y install docker-io ################################################ 进入容器命令 docker exec ...

  7. 开发者必看|Android 8.0 新特性及开发指南

    背景介绍 谷歌2017 I/O开发者大会今年将于5月17-19日在美国加州举办.大会将跟往年一样发布最新的 Android 系统,今年为 Android 8.0.谷歌在今年3 月21日发布 Andro ...

  8. jap 事务总结

    参考: JPA事务总结 2010年4月13日 - 从表11-2中可以看出,对于不同的EntityManager类型与所运行的环境,所支持的事务类型是不一样的. 其中两种情况下最为简单,一种是容器托管的 ...

  9. json和java bean的相互转换(使用fastjson)

    <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifac ...

  10. cnapckSurround c++builder Region 代码折叠快捷键

    C++Builder代码折叠 cnapckSurround c++builder Region 代码折叠快捷键,可以导入导出,IDE code edit,cnpack menu surround wi ...