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
题目大意 :题目中给出了几幅图,判断给出的矩阵能否有题目中的图片叠加而成。
题解:该题难在构图与题意上。如果能够由每个图片叠加而成那么一定会有个先后。也就是说,一定能用拓扑排序将其排列好。如果拓扑排序没有成功排出,输出 THESE WINDOWS ARE BROKEN。否则输出THESE WINDOWS ARE CLEAN
还有一个难点就是在构图上。我们只需要记录每个数字的左上角的坐标,然后进行搜索见图,即判断该数字本身位置有没有被覆盖,右边下边以及右下角有没有被覆盖。被覆盖的话,就用邻接矩阵标记为1.并记录节点的 入度
//判断所有位置的覆盖情况
//如果a覆盖b 则构造一条边edge[b][a]=1 最后得到一个图
//这个图一定是无环的 如果有环则表示a覆盖b b又覆盖a
//即显示不正常
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int N=1E5+;
int arr[][]; int arr2[][]={{,}, {,},{,},{,}, {,},{,},{,}, {,},{,},{,} };// 每个区域的左上角
int dir[][]={{,},{,},{,},{,}};//对应四个方向 本身,右边,下边,还有右下角 int map[][];
int in[N];
int main(){
string a;
while(cin>>a&&a!="ENDOFINPUT"){ memset(in,,sizeof(in));
memset(arr,,sizeof(arr));
memset(map,,sizeof(map)); for(int i=;i<=;i++)
for(int j=;j<=;j++){
scanf("%d",&arr[i][j]);
} string b;
cin>>b;
//建图
for(int i=;i<=;i++){
for(int j=;j<;j++){
int dx=arr2[i][]+dir[j][];
int dy=arr2[i][]+dir[j][];
int dz=arr[dx][dy];
if(dz!=i&&map[dz][i]==){
map[dz][i]=;
in[i]++;
}
}
} queue<int >que;
for(int i=;i<=;i++){
if(in[i]==){
que.push(i);
}
} int sum=;
while(que.size()){
int xx=que.front();
que.pop();
sum++;
for(int i=;i<=;i++){
if(map[xx][i]==){
in[i]--;
if(in[i]==){
que.push(i);
}
}
}
} if(sum==) puts("THESE WINDOWS ARE CLEAN");
else puts("THESE WINDOWS ARE BROKEN");
}
return ;
}

Windows Pains poj 2585的更多相关文章

  1. poj 2585 Window Pains 解题报告

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

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

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

  3. POJ 2585.Window Pains 拓扑排序

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

  4. POJ 2585 Window Pains 题解

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

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

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

  6. zoj 2193 poj 2585 Window Pains

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

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

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

  8. Window Pains(poj 2585)

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

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

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

随机推荐

  1. 第十四周java实验作业

    实验十四  Swing图形界面组件 实验时间 20178-11-29 1.实验目的与要求 (1) 掌握GUI布局管理器用法: 在java中的GUI应用 程序界面设计中,布局控制通过为容器设置布局管理器 ...

  2. 「面试指南」解读JavaScript原始数据类型

    JavaScript 有 7 种原始数据类型: String(字符型) Number(数值型) Boolean(布尔值型) Undefined Null Object(对象型) Symbol(符号型, ...

  3. RNN,GRU,LSTM

    2019-08-29 17:17:15 问题描述:比较RNN,GRU,LSTM. 问题求解: 循环神经网络 RNN 传统的RNN是维护了一个隐变量 ht 用来保存序列信息,ht 基于 xt 和 ht- ...

  4. java后台调用文件上传接口

    借鉴:https://blog.csdn.net/yjclsx/article/details/70675057 /** * 调用流程上传文件接口上传文件 * @param url * @param ...

  5. 如何删除Python中文本文件的文件内容?

    在python中: open('file.txt', 'w').close() 或者,如果你已经打开了一个文件: f = open('file.txt', 'r+') f.truncate(0) # ...

  6. 吴恩达最新TensorFlow专项课程开放注册,你离TF Boy只差这一步

    不需要 ML/DL 基础,不需要深奥数学背景,初学者和软件开发者也能快速掌握 TensorFlow.掌握人工智能应用的开发秘诀. 以前,吴恩达的机器学习课程和深度学习课程会介绍很多概念与知识,虽然也会 ...

  7. PHP7内核(八):深入理解字符串的实现

    在前面大致预览了常用变量的结构之后,我们今天来仔细的剖析一下字符串的具体实现. 一.字符串的结构 struct _zend_string { zend_refcounted_h gc; /* 字符串类 ...

  8. +load 和 +initialize

    APP 启动到执行 main 函数之前,程序就执行了很多代码. 执行顺序: 将程序依赖的动态链接库加载到内存 加载可执行文件中的所有符号,代码 runtime 解析被编译的符号代码 遍历所有的 cla ...

  9. 俩个对象的hashCode()相同,则equals()也一定为true,对吗?

    不对,俩个对象的hashCode()相同,equals()不一定为true. 代码示例: 1 String str1 = "通话"; 2 String str2 = "重 ...

  10. Docker容器入门-基本命令的使用

    目前容器技术使用相当广泛 不会或者没有使用过容器感觉都不像是个搞技术的 所以,我也就docker相关内容做一个整理 只有不断的学习,才能保持自己的竞争力 什么是容器? 容器是一种轻量级.可移植.自包含 ...