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. Magento2(麦进斗) docker 安装

    Magento 介绍 Magento(麦进斗)是一套专业开源的电子商务系统,采用php进行开发,使用Zend Framework框架.Magento设计得非常灵活,具有模块化架构体系和丰富的功能.易于 ...

  2. Java 访问修饰符大全详解

    鉴于笔试面试总会遇到,决心仔细认真梳理一下: 1:涉及的关键字:public,default(表示缺省),protected,private,static,final,abstract. 2:关键字含 ...

  3. 性能测试工具Jmeter你所不知道的内幕

    谈到性能测试,大家一定会联想到Jmeter和LoadRunner,这两款工具目前在国内使用的相当广泛,主要原因是Jmeter是开源免费,LoadRunner 11在现网中存在破解版本.商用型性能测试工 ...

  4. 干货系列之java注解

    干货系列之java注解 前言 java反射和注解在java里面很重要,但是很多人对这方面的知识理解不是很好,我来说说我自己对java反射和注解的理解,这两块内容本来应该出在一个博客文章里面讲解,但是由 ...

  5. 【总结】办公&编程&学习你可能需要这些小利器!

    偶然想到自己从最开始的编程小白,什么都不懂,看啥啥新鲜的时期,到现在颇有"蓦然回首,那人却在灯火阑珊处"的感觉,遂想整理一下这一路学习我个人发现的在办公.编程或者学新知识等方面针对 ...

  6. 推荐|近期热点机器学习git项目

    No1: InterpretML by Microsoft--Machine Learning Interpretability github地址:https://github.com/microso ...

  7. Colab笔记本能用英伟达Tesla T4了,谷歌的羊毛薅到酸爽

    谷歌出品的Colab笔记本,机器学习界薅羊毛神器,如今又有了新福利: 连英伟达最新一代机器学习GPU:Tesla T4都能免费蹭,穷苦羊毛党也顿时高端了起来. 英伟达的Tesla T4,是去年秋天才发 ...

  8. coding++:事务管理 隔离级别

    在声明事务时,只需要通过value属性指定配置的事务管理器名即可,例如:@Transactional(value="transactionManagerPrimary"). 除了指 ...

  9. spring 事务源码赏析(二)

    我们在spring 事务源码赏析(一) 中分析了spring事务是如何找到目标方法,并如何将事务的逻辑织入到我们的业务逻辑中.本篇我们将会看到spring事务的核心实现: 1.事务传播机制的实现 2. ...

  10. .NET Core 3.1 的REST 和gRPC 性能测试

    看到越南小哥 的github 上的Evaluating Performance of REST vs. gRPC , 使用的是.NET Core 3.0 , 今天我把它升级到.NET Core 3.1 ...