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. 代码生成器 CodeSmith 的使用(三)

    在第二篇中,介绍了用 codesmith 生成数据库中的一些字段,可生成的属性不够简洁,这次对上一次的版本进行重构,生成一些简洁的属性访问器.代码如下: Camel 规则: <%-- Name: ...

  2. python之socket编写

    Socket 类型 套接字格式: socket(family,type[,protocal]) 使用给定的地址族.套接字类型.协议编号(默认为0)来创建套接字. socket类型 描述 socket. ...

  3. [Flutter] 支持描边效果的Text

    新版的flutter已经自带这个功能了.TextSyle 中一个shadow . 目前flutter中没找到很好的办法给Text增加描边.自己扩展了一个TextEx,可以实现简单的描边效果,能满足大部 ...

  4. bootstrap file input 多图片上传编辑THINKPHP5

    {layout name="layout" title="文章添加" /} <form id="defaultForm" role=& ...

  5. OpenCL 管道

    ▶ 按书上写的管道的代码,需要使用 OpenCL2.0 的平台和设备,目前编译不通过,暂时不知道是什么问题,先把代码堆上来,以后换了新的设备再说 ● 程序主要功能:用主机上的数组 srcHost 创建 ...

  6. 《GPU高性能编程CUDA实战》第九章 原子性

    ▶ 本章介绍了原子操作,给出了基于原子操作的直方图计算的例子. ● 章节代码 #include <stdio.h> #include "cuda_runtime.h" ...

  7. 0_Simple__simpleTemplates + 0_Simple__simpleTemplates_nvrtc

    使用 C++ 的模板 ▶ 源代码:静态使用 // sharedmem.cuh #ifndef _SHAREDMEM_H_ #define _SHAREDMEM_H_ // SharedMemory 的 ...

  8. maven - 配置强制从指定仓库拉取jar包

    从官方maven仓库拉取依赖,会超级慢.可配置settings.xml,强制从私服拉取 <mirrors> <mirror> <id>nexus-releases& ...

  9. 相对固定位置 relative absolute

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. delegate() 事件绑定 事件委托

    定义和用法 delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数. 使用 delegate() 方法的事件处理程序适用于当前或未来 ...