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. hadoop的shell总结

    ls命令(文件内容) 列出系统跟目录下的目录和文件 Hadoop fs -ls / 列出文件系统所有的目录和文件 Hadoop fs -ls -R / cat命令(列出文档内容) Hadoop fs ...

  2. SharePoint 2013 安装配置(3-2)

    第三部分SQL Server后端配置篇幅较长,上一篇介绍SQL Server 前提条件及安装(3-1),这篇分享SQL Server功能安装配置,请参考以下步骤. 10.在“安装角色”屏幕上,选择“S ...

  3. BLL-IDAL-DAL的关系

    BLL  实现 IDAL  是一个接口 DAL 实现方法 BLL 调用IDAL 的方法 IDAL中的方法   在 DAL中必须实现 使用的方法  调用BLL的方法就可以

  4. Ubuntu 16.04 换国内源

    官方渠道,图形界面,操作简单,可以说对新手及其友好!! 依次打开:搜索,软件与更新,第一个和第三个勾上,下载自,其它,然后在中国条目下选择你想使用的镜像站点,然后点“选择服务器”,然乎点击“关闭”,选 ...

  5. volatile引发的一系列血案

    最早读<深入理解java虚拟机>对于volatile部分就没有读明白,最近重新拿来研究并记录一些理解 理解volatile前需要把以下这些概念或内容理解: 1.JMM内存模型 2.并发编程 ...

  6. C++链表简单的应用

    学生管理系统,输入学生的姓名和学号,然后再输出: #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <stdlib ...

  7. bootstrap 警告(Alerts)

    本章将讲解警告(Alerts)以及bootstrap所提供的用于警告的class类.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添 ...

  8. Android读书笔记三

    通过一章的学习体会到Git的重要性,因为想要获取开源的源代码,必须要使用Git,而且Linux内核完全是由Git管理的.Git是对源代码进行管理,在使用之前需要先安装,命令是 (1)apt-get i ...

  9. Matlab学习记录(函数)

    Matlab中的内建函数 Matlab自定义函数 用function构造函数 用inline构造函数 用syms构造符号函数 多项式相关函数 polyvalx convx 向量和矩阵运算函数 向量运算 ...

  10. NOIP2018 - 暑期博客整理

    暑假写的一些博客复习一遍.顺便再写一遍或者以现在的角度补充一点东西. 盛暑七月 初涉基环外向树dp&&bzoj1040: [ZJOI2008]骑士 比较经典的基环外向树dp.可以借鉴的 ...