Window Pains
http://poj.org/problem?id=2585
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1614 | Accepted: 806 |
Description
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
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
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
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
参考代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
const int ms=;
int screen[ms][ms];
string cover[ms][ms];
bool exist[];
int id[];
bool link[][];
int t;
string s; void calc()
{
int k,i,j;
for(i=;i<ms;i++)
for(j=;j<ms;j++)
cover[i][j].erase();
for(k=;k<=;k++)
{
i=(k-)/;
j=(k-)%;
cover[i][j]+=char(k+'');
cover[i][j+]+=char(k+'');
cover[i+][j]+=char(k+'');
cover[i+][j+]+=char(k+'');
}
return ;
} void init()
{
int i,j,k;
memset(exist,,sizeof(exist));
memset(link,,sizeof(link));
memset(id,,sizeof(id));
t=;
for(i=;i<ms;i++)
for(j=;j<ms;j++)
{
cin>>k;
screen[i][j]=k;
if(!exist[k])
t++;
exist[k]=true;
}
return;
} void build()
{
int i,j,k;
for(i=;i<ms;i++)
{
for(j=;j<ms;j++)
{
for(k=;k<cover[i][j].length();k++)
{
if(!link[screen[i][j]][cover[i][j][k]-'']&&screen[i][j]!=cover[i][j][k]-'')
{
id[cover[i][j][k]-'']++;
link[screen[i][j]][cover[i][j][k]-'']=true;
}
}
}
}
return ;
}
bool check()
{
int i,j,k;
for(k=;k<t;k++)
{
i=;
while(!exist[i]||(i<=&&id[i]>))
i++;
if(i>)
return false;
exist[i]=false;
for(j=;j<=;j++)
if(exist[j]&&link[i][j])
id[j]--;
}
return true;
}
int main()
{
calc();
while(cin>>s)
{
if(s=="ENDOFINPUT")
break;
init();
build();
if(check())
cout<<"THESE WINDOWS ARE CLEAN"<<endl;
else
cout<<"THESE WINDOWS ARE BROKEN"<<endl;
cin>>s;
}
return ;
}
Window Pains的更多相关文章
- POJ 2585:Window Pains(拓扑排序)
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2524 Accepted: 1284 Desc ...
- POJ 2585.Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1888 Accepted: 944 Descr ...
- POJ2585 Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1843 Accepted: 919 Descr ...
- poj 2585 Window Pains 解题报告
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2027 Accepted: 1025 Desc ...
- 【POJ 2585】Window Pains 拓扑排序
Description . . . and so on . . . Unfortunately, Boudreaux's computer is very unreliable and crashes ...
- zoj 2193 poj 2585 Window Pains
拓扑排序. 深刻体会:ACM比赛的精髓之处不在于学了某个算法或数据结构,而在于知道这个知识点但不知道这个问题可以用这个知识去解决!一看题目,根本想不到是拓扑排序.T_T...... #include& ...
- POJ 2585 Window Pains 题解
链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上 ...
- poj 2585 Window Pains 暴力枚举排列
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...
- Window Pains(poj 2585)
题意: 一个屏幕要同时打开9个窗口,每个窗口是2*2的矩阵,整个屏幕大小是9*9,每个窗口位置固定. 但是是否被激活(即完整显示出来)不确定. 给定屏幕状态,问是否可以实现显示. 分析:拓扑排序,把完 ...
随机推荐
- codevs3044 线段树+扫描线
3044 矩形面积求并 http://hzwer.com/879.html 扫描线 // #pragma comment(linker, "/STACK:1024000000,1024000 ...
- Java8新特性 1——利用流和Lambda表达式操作集合
Java8中可以用简洁的代码来操作集合,比如List,Map,他们的实现ArrayList.以此来实现Java8的充分利用CPU的目标. 流和Lambda表达式都是Java8中的新特性.流可以实现对集 ...
- 用Gitolite 构建 Git 服务器
转载 Gitolite 构建 Git 服务器 作者: 北京群英汇信息技术有限公司 网址: http://www.ossxp.com/ 版本: 0.1-1 日期: 2010-10-07 14:52:19 ...
- 一些常用的IOS开发网站
开发教程: 即便过了入门阶段,还是要经常看看一些不错的实例教程.1.http://mobile.tutsplus.com/category/tutorials/iphone/ 比较新的一个网站,以前没 ...
- POJ 2185 Milking Grid(KMP)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
- oracle 监测数据库是否存在指定字段
public static bool ExistColumn(string tableName, string columnName, string connStr) { using (OracleC ...
- contest7.20(暴力专练)
此次练习的地址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#overview 密码 acmore Problem A(P ...
- Unity3D之UGUI学习笔记(三):EventSystem
在UGUI中,EventSystem实现了所有关于交互方面的功能,和NGUI不一样的地方是,我们终于可以摆脱添加Box Collider了! 下面我们来学习一下. 对于按钮来说,直接有onClick的 ...
- [c++]this指针理解
#include <iostream> using namespace std; /** * this 指针理解 */ class A{ int i; public: void hello ...
- radio select的 option使用
1 radio的使用 <td id="sex">性别: <input type="radio" name=&quo ...