http://poj.org/problem?id=2585

Window Pains
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1614   Accepted: 806

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
参考代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
const int ms=;
int screen[ms][ms];
string cover[ms][ms];
bool exist[];
int id[];
bool link[][];
int t;
string s; void calc()
{
int k,i,j;
for(i=;i<ms;i++)
for(j=;j<ms;j++)
cover[i][j].erase();
for(k=;k<=;k++)
{
i=(k-)/;
j=(k-)%;
cover[i][j]+=char(k+'');
cover[i][j+]+=char(k+'');
cover[i+][j]+=char(k+'');
cover[i+][j+]+=char(k+'');
}
return ;
} void init()
{
int i,j,k;
memset(exist,,sizeof(exist));
memset(link,,sizeof(link));
memset(id,,sizeof(id));
t=;
for(i=;i<ms;i++)
for(j=;j<ms;j++)
{
cin>>k;
screen[i][j]=k;
if(!exist[k])
t++;
exist[k]=true;
}
return;
} void build()
{
int i,j,k;
for(i=;i<ms;i++)
{
for(j=;j<ms;j++)
{
for(k=;k<cover[i][j].length();k++)
{
if(!link[screen[i][j]][cover[i][j][k]-'']&&screen[i][j]!=cover[i][j][k]-'')
{
id[cover[i][j][k]-'']++;
link[screen[i][j]][cover[i][j][k]-'']=true;
}
}
}
}
return ;
}
bool check()
{
int i,j,k;
for(k=;k<t;k++)
{
i=;
while(!exist[i]||(i<=&&id[i]>))
i++;
if(i>)
return false;
exist[i]=false;
for(j=;j<=;j++)
if(exist[j]&&link[i][j])
id[j]--;
}
return true;
}
int main()
{
calc();
while(cin>>s)
{
if(s=="ENDOFINPUT")
break;
init();
build();
if(check())
cout<<"THESE WINDOWS ARE CLEAN"<<endl;
else
cout<<"THESE WINDOWS ARE BROKEN"<<endl;
cin>>s;
}
return ;
}

Window Pains的更多相关文章

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

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

  2. POJ 2585.Window Pains 拓扑排序

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

  3. POJ2585 Window Pains 拓扑排序

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1843   Accepted: 919 Descr ...

  4. poj 2585 Window Pains 解题报告

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

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

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

  6. zoj 2193 poj 2585 Window Pains

    拓扑排序. 深刻体会:ACM比赛的精髓之处不在于学了某个算法或数据结构,而在于知道这个知识点但不知道这个问题可以用这个知识去解决!一看题目,根本想不到是拓扑排序.T_T...... #include& ...

  7. POJ 2585 Window Pains 题解

    链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上 ...

  8. poj 2585 Window Pains 暴力枚举排列

    题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...

  9. Window Pains(poj 2585)

    题意: 一个屏幕要同时打开9个窗口,每个窗口是2*2的矩阵,整个屏幕大小是9*9,每个窗口位置固定. 但是是否被激活(即完整显示出来)不确定. 给定屏幕状态,问是否可以实现显示. 分析:拓扑排序,把完 ...

随机推荐

  1. Tkinter教程之Frame篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811339 '''Tkinter教程之Frame篇'''#Frame就是屏幕上的一块矩形区域, ...

  2. 《Genesis-3D开源游戏引擎-官方录制系列视频教程:进阶实例篇》

    注:本系列教程仅针对引擎编辑器:v1.2.2及以下版本 G3D进阶实例   第四课<2D编辑与脚本的统一入口> 使用G3D完成一个简单的类飞机大战游戏,介绍了G3D2d游戏制作的流程包括: ...

  3. Hold住:坚持的智慧

    这类励志的书读完时,感觉很激励人,可读完后总觉得空空的.同样这本书读完后没特别的感觉(也许书中的思想已影响了我,只是目前还说不太清楚),只感觉有些句子很有感觉,做个汇总: 1.      荀子有言:“ ...

  4. 将android Settings 源码 导入到 eclipse工程

    1.  新建 android 项目 拷贝源码/packages/apps/Settings到你的其它目录. 在eclipse中,新建项目,但是要从exitting source选择: 2. 导入相关的 ...

  5. linux内核书籍

    1, 关于操作系统理论的最初级的知识.不需要通读并理解<操作系统概念><现代操作系统>等巨著,但总要知道分时(time-shared)和实时(real-time)的区别是什么, ...

  6. How to include JavaScript file in JSF

    In JSF 2.0, you can use <h:outputScript /> tag to render a HTML "script" element, an ...

  7. HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...

  8. CentOS查看系统信息-CentOS查看命令

    一:查看cpu more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...

  9. mongoDB在windows下基于配置文件的安装和权限配置方式

    下载mongoDB  http://www.mongodb.org/downloads 根据操作系统,选择需要下载的安装包 添加mongodb 安装目录 将解压的文件夹中内容拷贝,存放在想要安装的文件 ...

  10. 织梦dedecms后台添加图片style全部都变成st<x>yle的解决办法

    可乐站长在建站的时候,上传缩略图喜欢输入图片路径,不喜欢上传图片,有几次我上传图片路径为:/style/image/**.jpg,然后返回修改后,图片为路径却为:/st<x>yle/ima ...