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. python爬虫之路——对字符串的处理

    对字符串的处理分类:分段,连接,剔除,提取,综合 连接:+,* +(加法)的使用 a='i' b=' love' c=' you' print(a+b+c) #return i love you *( ...

  2. JDBC + SAP云平台 = 运行在云端的数据库应用

    在前一篇文章JPA + EclipseLink + SAP云平台 = 运行在云端的数据库应用我介绍了如何通过JPA和EclipseLink操作部署在SAP云平台上的HANA数据库实例. 在这篇文章里, ...

  3. CMDB API验证

    CMDB API验证 为什么做API验证 API验证是防止数据在传输的过程中,保证数据不被篡改 如何设计的API验证 灵感来源于Torando中加密Cookie的源码,主要是生成加密的随机字符串. M ...

  4. docker单主机网络

    当你安装Docker时,它会自动创建三个网络.你可以使用以下docker network ls命令列出这些网络: [root@localhost ~]# docker network ls NETWO ...

  5. GCD之dispatch queue

    GCD之dispatch queue iOS中多线程编程工具主要有: NSThread NSOperation GCD 这三种方法都简单易用,各有千秋.但无疑GCD是最有诱惑力的,因为其本身是appl ...

  6. C语言输出多位小数

    #include<stdio.h>#include<stdlib.h>int main(){int i=0;int m=19;int n=3;int s=0;s=m/n;pri ...

  7. Golang tcp转发 remoteAddr错误

    Golang tcp 转发 第一版本 accept获取的Conn里的localAddr做为源地址,remoteAddr来做为目的地址 // tcpForward package main import ...

  8. JAVA中文字符串编码--GBK转UTF-8

    转载自:https://www.cnblogs.com/yoyotl/p/5979200.html 一.乱码的原因 gbk的中文编码是一个汉字用[2]个字节表示,例如汉字“内部”的gbk编码16进制的 ...

  9. Linux基础学习-crond系统计划任务

    系统计划任务 大部分系统管理工作都是通过定期自动执行某个脚本来完成的,那么如何定期执行某个脚本,从而实现运维的自动化,这就要借助Linux的cron功能了. 计划任务分为一次性计划任务和周期性计划任务 ...

  10. Spring Cloud构建微服务架构(二)分布式配置中心

     注:此文不适合0基础学习者直接阅读,请先完整的将作者关于微服务的博文全部阅读一遍,如果还有疑问,可以再来阅读此文,地址:http://blog.csdn.net/sosfnima/article/d ...