Window Pains

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2524   Accepted: 1284

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

题意

有9个程序窗口在4*4的矩阵中,每个程序窗口占用2*2矩阵的空间,编号为1~9。如下图(画的有点乱,应该能看懂)

在这些程序窗口中存在相互覆盖的关系,给出9*9的数字矩阵,每个数字表示程序窗口。问这样的相互覆盖关系是否合理

思路

拓扑排序模板题。但是建图太难了T_T,建好图进行拓扑排序,判断排序之后还有没有相连的边就行了

样例中的建好的图如下图(图片来自http://www.cnblogs.com/pony1993/archive/2012/08/16/2641904.html

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e3+10;
using namespace std;
int a[maxn][maxn];
int vis[maxn];
int b[maxn][maxn];
void toposort()
{
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
if(vis[j]==0)
{
vis[j]--;
for(int k=1;k<=9;k++)
{
if(b[j][k])
{
b[j][k]--;
vis[k]--;
}
}
break;
}
}
}
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
string str;
string st;
while(cin>>str)
{
ms(vis);
ms(a);
ms(b);
if(str=="ENDOFINPUT")
break;
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++)
cin>>a[i][j];
cin>>st;
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
for(int ii=0;ii<2;ii++)
{
for(int jj=0;jj<2;jj++)
{
if(a[i+ii][j+jj]==j+(i-1)*3)
continue;
else if(b[a[i+ii][j+jj]][j+(i-1)*3]==0)
{
b[a[i+ii][j+jj]][j+(i-1)*3]=1;
vis[j+(i-1)*3]++;
}
}
}
}
}
toposort();
int flag=0;
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
flag+=b[i][j];
}
}
if(flag)
cout<<"THESE WINDOWS ARE BROKEN"<<endl;
else
cout<<"THESE WINDOWS ARE CLEAN"<<endl;
}
return 0;
}

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 拓扑排序

    Description . . . and so on . . . Unfortunately, Boudreaux's computer is very unreliable and crashes ...

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

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

  4. poj 2585 Window Pains 解题报告

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

  5. POJ2585 Window Pains 拓扑排序

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

  6. zoj 2193 poj 2585 Window Pains

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

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

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

  8. POJ 2585 Window Pains 题解

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

  9. [poj2585]Window Pains_拓扑排序

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

  10. POJ 2367 (裸拓扑排序)

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

随机推荐

  1. Oracle学习笔记(二)——临时表

    在针对大数据量的多表级联查询或复杂事务处理的时候,引入Oracle临时表是一种不错的策略.因此,在解决实际需求时经常会遇到需要使用存储过程和临时表相互配合的情况.下面就Oracle如何创建临时表以及注 ...

  2. HDU2017新生赛 友好整数

    思路: 很简单的一个状态压缩,比赛时没想出来. 最多只有2^10个状态,n^2暴力一下也就1e6. 代码: #include<bits/stdc++.h> using namespace ...

  3. 最大交换 Maximum Swap

    2018-07-28 16:52:20 问题描述: 问题求解: 使用bucket数组来记录每个数最后出现的位置,然后从左向右遍历一遍即可. public int maximumSwap(int num ...

  4. inputsimulator - Windows Input Simulator

    窗体输入模拟器提供一个基于 win32 SendInput  方法的 模拟键盘鼠标输入的.net 接口.windows 输入模拟器可用于 WPF.windows 窗体和控制台应用程序, 实现模拟任意按 ...

  5. Yet Another Ball Problem CodeForces - 1118E (简单构造)

    大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...

  6. mysql 随机获取数据并插入到数据库中

    insert into result (user_id, activity_id, number) select user_id, activity_id from `activity_record` ...

  7. OAF系统更新默认LOGO图标和主页环境描述

    更新EBS  OAF系统中默认的LOGO图标和主页的环境描述 左上角的ORACLE图片位置在  登录界面左上角oracle LOGO图片为GIF格式,大小155*20 背景透明.文件名为:FNDSSC ...

  8. Linux的三种网络适配器

    Linux的三种网络适配器 分别为:桥接模式(Bridged),NAT模式,仅主机模式. 仅主机模式:        2>NAT模式 NAT 是虚拟机和本地网络使用一个ip地址 3>桥接模 ...

  9. 微信小程序绑定数据(微信小程序交流群:604788754)

    在小程序开发中,用js绑定数据时,明明没报错,但页面没有显示绑定的数据内容.这有可能是相对应的js绑定数据的一些变量名字的问题.遇到这种情况.可以从新建立一个新的demo页面.把问题页面相对应的js. ...

  10. PHP:第一章——PHP中的关键字

    <?php //PHP关键词 /* and //php中的逻辑与运算符.(和) or //php中的逻辑或运算符.(或) xor //php中的逻辑异或.(异或) __FILE__ //php中 ...