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,每个窗口位置固定. 但是是否被激活(即完整显示出来)不确定. 给定屏幕状态,问是否可以实现显示. 分析:拓扑排序,把完 ...
随机推荐
- leetcode—3sum
1.题目描述 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...
- [转]天龙八部服务器端Lua脚本系统
一.Lua脚本功能接口 1. LuaInterface.h/.cpp声明和实现LuaInterface. LuaInterface成员如下: //脚本引擎 FoxLuaScriptmLua ; //注 ...
- Bone.io是一个轻量级的框架构建高性能实时单页HTML5应用程序
Bone.io允许你使用HTML5 WebSockets构建实时应用程序,提供“热”数据到浏览器.这使您可以轻松地构建丰富的,高度响应的用户界面. 项目主页:http://www.open-open. ...
- JVM内存结构
前言 在Java语言开发过程中,out of memory错误是很常见的一种错误.对于JVM的内存结构有更深入的了解,更更好的帮我们排查此类问题,有效的避免此类问题发生.在JAVA 8中内存结构有进行 ...
- homework_01
一. 程序的架构和思路: 这段求解最大子数组之和的程序使用的主要思想是贪心算法,即每一步求出的都是当前的最优解. 首先这道题要分两种情况来讨论: 1)如果当前的输入中所有的数均为负数时,那么最后的解就 ...
- WinJS.Binding.List与kendo.data.ObservableArray
avalon0.8一个最大目标是实现对数组的深层监控,可是面临的困难重重,至今还没有什么起色.于是看一下其他两个MVVM框架的做法(knockout, emberjs, angular都不能监听家庭数 ...
- JSF 2 multiple select listbox example
In JSF, <h:selectManyListbox /> tag is used to render a multiple select listbox – HTML select ...
- Web 前端最佳实践
Web 最佳实践 前端 选择器 尽量使用ID选择器 基于Id的选择器:先使用ID选择器定位,然后再使用find方法精确查找 // Fast: $( "#container div ...
- Edit Box多行显示时如何使滚动条始终在下方
两种方法: ① CEdit *pEdit = ((CEdit*)GetDlgItem(IDC_EDIT_RXDATA)); pEdit->LineScroll(pEdit->GetLin ...
- 绑定线程到特定CPU处理器
参考这篇文章 http://blog.chinaunix.net/uid-27761170-id-5050258.html 代码如下: #define _GNU_SOURCE #include < ...