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. Hbase region查找过程

    HBase的table是该region切分的,client操作一个row的时候,如何知道这个row对应的region是在哪台Region server上呢?这里有个region location过程. ...

  2. PHP超全局变量、魔术变量和魔术方法

    PHP超全局变量 $_GET 通过get方式传递的值(通过 URL 参数传递给当前脚本的变量的数组.) $_POST 通过post形式传递的值(当 HTTP POST 请求的 Content-Type ...

  3. 登录控制 BaseController

    执行方法前 判断 sessin 登录信息 是否为空 ,空的话 返回 登录界面 并且给 LoginUser 赋值 public abstract class BaseController : Contr ...

  4. django之基于cookie和装饰器实现用户认证

    示例1 # Create your views here. user = "a" pwd = "a" def login(request): if reques ...

  5. 程序员的智囊库系列之3--分布式文件系统(Distributed file systems)

    程序员的智囊库系列之3--分布式文件系统(Distributed file systems) 这是程序员的智囊库系列的第三篇文章.上一篇文章本来打算介绍几个搭建网站的框架,但由于这部分的内容较多,还需 ...

  6. VA助手添加扩展文件后缀名

    Allow C/C++ files with a non-standard extension Follow these steps to make Visual Assist consider as ...

  7. css实现页面文字不换行、自动换行、强制换行

    强制不换行 div{ white-space:nowrap; } 自动换行 div{ word-wrap: break-word; word-break: normal; } 强制英文单词断行 div ...

  8. 【线段树 树链剖分 差分 经典技巧】loj#3046. 「ZJOI2019」语言【未完】

    还是来致敬一下那过往吧 题目分析 先丢代码 #include<bits/stdc++.h> ; ; ; struct node { int top,son,fa,tot; }a[maxn] ...

  9. [图文] Fedora 28 使用 Virt-Manager 创建 KVM 虚拟机以及 配置 KVM 虚拟机

    实验说明: 往后的许多实验都将以Linux平台下的 KVM虚拟机为主,所以不可少的就是 Virt-Manager 虚拟机管理器. 本章将对如何安装和使用Virt-Manager管理器进行讲解,并且会对 ...

  10. H5bulider中的微信支付配置注意事项

    一.云打包安卓自定义证书的生成: 签名算法名称: SHA1withRSA主体公共密钥算法:1024 位 RSA 密钥密钥库类型:JKS 1.下载JDK1.6安装,切换到bin目录,打开命令行: 2.生 ...