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

Description

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

Source

——————————————————我是分割线——————————————————
拓扑排序,绝世好题。
前5分钟只想出来暴搜方法
后来想到可以记录每个方格能被哪些窗口盖住
转化成图论问题,拓扑排序求环
有环就是死机,否则就是好的。
真是的,如果不是事先知道这题是拓扑排序,我就只会写一发搜索剪枝去骗分了.......
读入写错了,调了半个钟头。
 /*
Problem:poj 2585
OJ: POJ
User: S.B.S.
Time: 0 ms
Memory: 700 kb
Length: 1991 b
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<vector>
#include<list>
#include<map>
#define maxn 10001
#define F(i,j,k) for(int i=j;i<k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
#define maxm 2016
#define mod 1000000007
//#define LOCAL
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
int sc[][];
string cr[][];
bool vis[];
int in[];
bool g[][];
int t;
string s;
inline void init()
{
F(i,,)F(j,,) cr[i][j].erase();
F(k,,){
int i=(k-)/;
int j=(k-)%;
cr[i][j]+=char(k+'');
cr[i][j+]+=char(k+'');
cr[i+][j]+=char(k+'');
cr[i+][j+]+=char(k+'');
}
}
inline void input()
{
int i,j;
M(vis,);M(in,);M(g,);
t=;
int k;
F(i,,)F(j,,){
cin>>k;
sc[i][j]=k;
if(!vis[k]) t++;
vis[k]=true;
}
}
inline void build()
{
int a,b;
F(i,,)F(j,,)F(k,,cr[i][j].length())
{
if((!g[sc[i][j]][cr[i][j][k]-''])&&(sc[i][j]!=cr[i][j][k]-''))
{
g[sc[i][j]][cr[i][j][k]-'']=true;
in[cr[i][j][k]-'']++;
}
}
}
inline bool ok()
{
int i,j,k;
F(k,,t){
i=;
while(!vis[i]||(i<=&&in[i]>)) i++;
if(i>) return false;
vis[i]=false;
F(j,,){
if(vis[j]&&g[i][j]) in[j]--;
}
}
return true;
}
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
init();
while(cin>>s)
{
if(s=="ENDOFINPUT") break;
input();
build();
if(ok()) cout<<"THESE WINDOWS ARE CLEAN"<<endl;
else cout<<"THESE WINDOWS ARE BROKEN"<<endl;
cin>>s;
}
return ;
}

poj 2585

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 暴力枚举排列

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

  3. POJ 2585 Window Pains 题解

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

  4. zoj 2193 poj 2585 Window Pains

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

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

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

  6. 【原创】leetCodeOj --- Sliding Window Maximum 解题报告

    天,这题我已经没有底气高呼“水”了... 题目的地址: https://leetcode.com/problems/sliding-window-maximum/ 题目内容: Given an arr ...

  7. Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)

     http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...

  8. POJ 3126 Prime Path 解题报告(BFS & 双向BFS)

    题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...

  9. 【原创】poj ----- 2376 Cleaning Shifts 解题报告

    题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K ...

随机推荐

  1. php输出多余的空格或者空行

    1,文件是否有bom.可以通过脚步检测,或者利用notepa++打开,查看编码格式. 2.  <?php echo 'something'; ?>  或许是你的php标签外,有空格或者空行 ...

  2. 关于日志API接口中流量的使用。

    现状: 目前服务器使用带宽是2M,那么最大上行流量应该是250kb/s,而通过日志发现目前最大并发流量是350kb/s. 问题: 看到以上的结果时,我当时的疑问是最大并发流量超过了服务器最大上行流量, ...

  3. [js]变量与数据类型篇

    一.变量 在JavaScript中就用一个变量名表示变量,变量名是大小写英文.数字.$和_的组合,不能用数字开头.变量名也不能是JavaScript的关键字: 1.变量的声明 (1)var:申明一个变 ...

  4. 自然语言处理系列-4条件随机场(CRF)及其tensorflow实现

    前些天与一位NLP大牛交流,请教其如何提升技术水平,其跟我讲务必要重视“NLP的最基本知识”的掌握.掌握好最基本的模型理论,不管是对日常工作和后续论文的发表都有重要的意义.小Dream听了不禁心里一颤 ...

  5. github下载项目

  6. springBoot 自动配置原理

    在之前文章中说过,springBoot会根据jar包去添加许多的自动配置,本文就来说说为什么会自动配置,自动配置的原理时什么? springBoot在运行SpringApplication对象实例化时 ...

  7. 社会主义核心价值观js代码

    效果如下: 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  8. [BZOJ5287][HNOI2018]毒瘤(虚树DP)

    暴力枚举非树边取值做DP可得75. 注意到每次枚举出一个容斥状态的时候,都要做大量重复操作. 建立虚树,预处理出虚树上两点间的转移系数.也可动态DP解决. 树上倍增.动态DP.虚树DP似乎是这种问题的 ...

  9. 关于void main()的误区

    很多人甚至市面上的一些书籍,都使用了void main( ) ,其实这是错误的.C/C++ 中从来没有定义过void main( ) .C++ 之父 Bjarne Stroustrup 在他的主页上的 ...

  10. mysql长连接

    长连接是干嘛的:  它是做连接复用的: 在openresty中的lua-resty-mysql 里 connect方法去连接mysql时会去ngx_lua cosocket连接池中寻找是否有可用连接 ...