Description

. . . 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
-----------------------------------------------------------------------------
最早想到的是dfs 从最上面一层倒着往回推,但最后没法记录点了.....
其实就是个拓扑排序的水题.....
主要是建边:枚举9个炮台,如果在自己射程区域内不是自己,说明被覆盖,因此说明这个颜色是当前颜色的先决条件,
于是连一条边。(开始理解为只要不是自己就连边,结果根本没有入度为0的边23333
然后跑一遍拓扑排序,如果没成环就成功了,成环就失败。
这是代码:
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#define N 20
using namespace std;
struct node
{
int u,v,nxt;
}e[N*];
int first[N],cnt;
void ade(int u,int v)
{
e[++cnt].nxt=first[u]; first[u]=cnt;
e[cnt].u=u; e[cnt].v=v;
}
int ru[N],cnnt;
int dir[][]= {,, ,, ,, ,};
int local[][]= {-,-, ,, ,, ,, ,, ,, ,, ,, ,, ,};
void topsort()
{
priority_queue<int>q;
for(int i=;i<=;i++)
if(ru[i]==) q.push(i);
while(!q.empty())
{
int x=q.top(); q.pop();
++cnnt;
// cout<<cnnt<<" ";
for(int i=first[x];i;i=e[i].nxt)
{
int v=e[i].v;
ru[v]--;
if(ru[v]==) q.push(v);
}
}
if(cnnt!=) printf("THESE WINDOWS ARE BROKEN\n");
else cout<<"THESE WINDOWS ARE CLEAN"<<endl;
}
int a[][];
bool vis[N][N];
int main()
{
char str[];
while(scanf("%s",str),strcmp(str,"ENDOFINPUT"))
{
for(int i=;i<;i++)
for(int j=;j<;j++)
scanf("%d",&a[i][j]);
scanf("%s",str);
memset(e,,sizeof(e));
memset(vis,,sizeof(vis));
memset(first,,sizeof(first));
memset(ru,,sizeof(ru));
cnt=cnnt=;
for(int k=;k<=;k++)
for(int i=;i<;i++)//在自己射程区域内不是自己->被覆盖
{
int x=local[k][]+dir[i][];
int y=local[k][]+dir[i][];
int now=a[x][y];
if(k!=now&&!vis[k][now])
{
vis[k][now]=;
ade(k,now);
ru[now]++;
}
}
topsort();
}
return ;
}

【POJ 2585】Window Pains 拓扑排序的更多相关文章

  1. POJ 2585.Window Pains 拓扑排序

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

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

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

  3. poj 2585 Window Pains 解题报告

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

  4. POJ2585 Window Pains 拓扑排序

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

  5. zoj 2193 poj 2585 Window Pains

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

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

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

  7. POJ 2585 Window Pains 题解

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

  8. [poj2585]Window Pains_拓扑排序

    Window Pains poj-2585 题目大意:给出一个4*4的方格表,由9种数字组成.其中,每一种数字只会出现在特定的位置,后出现的数字会覆盖之前在当前方格表内出现的.询问当前给出的方格表是否 ...

  9. POJ 2367 (裸拓扑排序)

    http://poj.org/problem?id=2367 题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...

随机推荐

  1. GreenDao 数据库升级 连接多个DB文件 或者指定不同的model&dao目录

    相信很多人都用过greenDao 今天 我抽空总结下使用的时候一些小东西吧 废话不多说 下边就GreenDao 的使用遇到的问题以及解决方案记录一下吧. 1.greendao 指定不同的生成目录: S ...

  2. HDU 4283 You Are the One (区间DP,经典)

    题意: 某校举行一场非诚勿扰,给定一个出场序列,表示n个人的屌丝值,如果他是第k个出场的,他的不满意度为(k-1)*diao[i].为了让所有人的屌丝值之和更小,导演设置一个栈,可以将部分人装进栈中, ...

  3. UVA 536 TreeRocvery 树重建 (递归)

    根据先序历遍和中序历遍输出后序历遍,并不需要真的建树,直接递归解决 #include<cstdio> #include<cstring> ; char preOrder[N]; ...

  4. ansible 任务委派 delegate_to

    ansible 任务委派功能delegate_to run_noce: true  在一个主机上面只执行一次一个任务. ,如果没有这个参数的话,每个playbook中的组的主机都会执行一次. 我们有的 ...

  5. 1968: C/C++经典程序训练6---歌德巴赫猜想的证明

    1968: C/C++经典程序训练6---歌德巴赫猜想的证明 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1165  Solved: 499[Submi ...

  6. 【转】Popclip的JSON格式化扩展

    http://liuyunclouder.github.io/2016/09/29/JSONizer:Popclip的JSON格式化扩展 作为一个MAC党,不好好利用MAC的神兵利器,简直就是罪过.A ...

  7. SC || Chapter 3

    ┉┉∞ ∞┉┉┉┉∞ ∞┉┉┉∞ ∞┉┉ 基本数据类型 && 对象数据类型 基本数据类型(int char long) 在栈中分配内存,不可变 对象数据类型(String BigInt ...

  8. 使用notepad++远程编辑Linux文档

    上一篇中,我写了如何使用使用ftp服务器实现很方便的通信,这一篇我分享一个使用notepad++的一个NPPFTP插件远程编辑Linux中的文档的小技巧. 首先要确保你的Linux的ftp服务已经打开 ...

  9. javaweb基础(3)_tomcat下部署项目

    一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命令的用法如下:

  10. mac Parallels Desttop 13 win7/win8 无法连接网络

    把 “源” 从共享网络改为"Wi-Fi" 在mac 这边点击菜单栏windows图标,选配置(如果没有配置,点控制中心,在点控制中心的齿轮,)选 硬件 找到网络 解锁,上边第一行就 ...