POJ 2585:Window Pains(拓扑排序)
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:
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
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:
|
If window 4 were then brought to the foreground: |
|
. . . 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:
- Start line - A single line:
START - 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.
- 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(拓扑排序)的更多相关文章
- POJ 2585.Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1888 Accepted: 944 Descr ...
- 【POJ 2585】Window Pains 拓扑排序
Description . . . and so on . . . Unfortunately, Boudreaux's computer is very unreliable and crashes ...
- [POJ 2585] Window Pains 拓朴排序
题意:你现在有9个2*2的窗口在4*4的屏幕上面,由于这9这小窗口叠放顺序不固定,所以在4*4屏幕上有些窗口只会露出来一部分. 如果电脑坏了的话,那么那个屏幕上的各小窗口叠放会出现错误.你的任务就是判 ...
- poj 2585 Window Pains 解题报告
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2027 Accepted: 1025 Desc ...
- POJ2585 Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1843 Accepted: 919 Descr ...
- zoj 2193 poj 2585 Window Pains
拓扑排序. 深刻体会:ACM比赛的精髓之处不在于学了某个算法或数据结构,而在于知道这个知识点但不知道这个问题可以用这个知识去解决!一看题目,根本想不到是拓扑排序.T_T...... #include& ...
- poj 2585 Window Pains 暴力枚举排列
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...
- POJ 2585 Window Pains 题解
链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上 ...
- [poj2585]Window Pains_拓扑排序
Window Pains poj-2585 题目大意:给出一个4*4的方格表,由9种数字组成.其中,每一种数字只会出现在特定的位置,后出现的数字会覆盖之前在当前方格表内出现的.询问当前给出的方格表是否 ...
- POJ 2367 (裸拓扑排序)
http://poj.org/problem?id=2367 题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...
随机推荐
- Codeforces 913D - Too Easy Problems
913D - Too Easy Problems 思路:二分check k 代码: #include<bits/stdc++.h> using namespace std; #define ...
- Lua中元表的学习
--table 中我们可以访问对应的key来得到value值,但是却无法对两个 table 进行操作. --元表(Metatable),允许我们改变table的行为,可以对两个table进行操作 -- ...
- java 路径分隔符File.separator 以及 路径两种写法"/"和"\\"
一.File.separator File file=new File(); 这句是新建一个文件.file.separator这个代表系统目录中的间隔符,说白了就是斜线,不过有时候需要双线,有时候是单 ...
- 什么是SQL游标?
1.1游标的概念 游标(Cursor)它使用户可逐行访问由SQL Server返回的结果集.使用游标(cursor)的一个主要的原因就是把集合操作转换成单个记录处理方式.用SQL语言从数据库中检索数据 ...
- Vue.js教程--基础2(事件处理 表单输入绑定
事件处理 表单输入绑定 事件处理 监听v-on 监听 DOM 事件,并在触发时运行一些 JavaScript 代码. 可以在v-on:click=''加内联语句. 有时也需要在内联语句处理器中访问原始 ...
- hpu1165 贪心
1165: 最少的需求 [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 12 解决: 4 状态 题目描述 小Q开了一家餐厅,最近生意非常火爆. 假设有N N 个预订信息,第i i ...
- SQL Server日志清空方法
1.清空日志:DUMP TRANSACTION databasename WITH NO_LOG 2.截断事务日志:BACKUP LOG databasename WITH ...
- zabbix LLD 自定义脚本
一 前言 二 懒人必备zabbix监控之 LLD (low level discovery) 本次的教程是我想监控kafka的消费情况,举个栗子 [root@VM_0_98_centos bin]# ...
- [Leetcode] Unique binary search trees 唯一二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- PHP:第一章——PHP中常量和预定义常量
<?php /*****************************************************/ //1.常量的定义 //常量:声明一次后长期不变的量,以字母或下划线开 ...