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. 从celery rabbitmq with docker-compose 引出对容器、依赖注入、TDD的感悟

    用docker配置项目管理系统taiga的时候,不是我一个人遇到这个问题.https://github.com/douglasmiranda/docker-taiga/issues/5 问题描述: 用 ...

  2. 算法笔记--2-sat

    强连通分量的应用,详见<挑战程序设计>P324 例题1:HDU Peaceful Commission 思路:强连通分量分解,看有没有两个同一个国家的代表在一个强连通分量里,如果有,就是N ...

  3. HTML提交方式post和get区别(实验)

    HTML提交方式post和get区别(实验) 一.post和get区别 get提交,提交的信息都显示在地址栏中. post提交,提交的信息不显示地址栏中,显示在消息体中. 二.客户端代码 <!D ...

  4. python模块——socket (实现简单的C/S架构端通信操作CMD)

    # 服务端代码#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "loki" import socket impo ...

  5. LeetCode--202--快乐数

    问题描述: 编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变 ...

  6. oracle使用(1)

    纯粹是记录工作中使用的分析函数或是语法点,不做其他用处. (1) with as 先举个例子吧: 有两张表,分别为A.B,求得一个字段的值先在表A中寻找,如果A表中存在数据,则输出A表的值:如果A表中 ...

  7. 在linux下出现cannot restore segment prot after reloc: Permission denied

    应用程序连接oracle的库时会出现如下错误:XXXXX:: error while loading shared libraries: /usr/local/oracle/product/10.2. ...

  8. EBS标准的查看供应商地址

    --获取供应商PARTY_ID SELECT * FROM HZ_PARTIES HP WHERE HP.PARTY_NAME='XXXXXX' VO数据源:oracle.apps.pos.suppl ...

  9. OAF 通过个性化 在标准事件上添加验证

    在实际的开发过程中,我们经常会遇到以下情况: 在执行标准的功能之前要对个性化的内容进行校验. 比如:在某个标准页面通过个性化添加了一个勾选框,在点击下一步的时候必须去验证此勾选框是否勾选. 具体实现如 ...

  10. quartz---(1)

    Quartz Quartz是什么? 简单的一些例子 Quartz是什么 简单的认为Quartz是是一个定时器. 1.1. 下载 http://www.quartz-scheduler.org/down ...