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. margin-top失效

    span标签是行类元素,只能margin-left,right 解决办法: 将span标签改为块级标签

  2. OpenCL 归约 1

    ▶ 照着书上的代码,写了几个一步归约的计算,只计算一步,将原数组归约到不超过 1024 个工作项 ● 代码 // kernel.cl __kernel void reduce01(__global u ...

  3. 机器学习入门-贝叶斯中文新闻分类任务 1. .map(做标签数字替换) 2.CountVectorizer(词频向量映射) 3.TfidfVectorizer(TFDIF向量映射) 4.MultinomialNB()贝叶斯模型构建

    1.map做一个标签的数字替换 2.vec = CountVectorizer(lowercase=False, max_features=4000)  # 从sklean.extract_featu ...

  4. sqlserver还原数据库

    该方法只针对同等级数据库,不能跨级   比如sqlserver2012还原到sqlserver2008会报错 用数据库日志文件对数据库进行还原一 将日志文件.mdf文件和.ldf文件copy放置在sq ...

  5. eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法

    关于 eclipse启动卡死的问题(eclipse上一次没有正确关闭,导致启动的时候卡死错误解决方法),自己常用的解决方法: 方案一(推荐使用,如果没有这个文件,就使用方案二): 到<works ...

  6. Python Spider 抓取猫眼电影TOP100

    """ 抓取猫眼电影TOP100 """ import re import time import requests from bs4 im ...

  7. jquery 获取和设置Select选项常用方法总结

    1.获取select 选中的 text:$("#cusChildTypeId").find("option:selected").text();$(" ...

  8. 迷你MVVM框架 avalonjs 学习教程13、模板引用

    稍为复杂一点的网站都是多个前端工程师合作而成,因此分工是必需的.简单一点的分工就是一个人负责一个频道,某个页面是由一个人全部做的:但如果涉及到一个页面非常复杂,需要多个人同时动工呢?于是到模板的出场时 ...

  9. JavaScript 累加求和练习 函数

    输入一个数,求从1加到这个数的和 主要代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

  10. mydqldump

    [mydqldump] One way to create a snapshot of the data in an existing master database is to use the my ...