POJ 2585.Window Pains 拓扑排序
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1888 | Accepted: 944 |
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
题目链接:http://poj.org/problem?id=2585
题意:有9个窗口把一个窗口调到最前面,它的所有的方格都位于最前面,覆盖其他窗口与它公用的方格。输入所有的方格的状态,判断是否正确。
思路:标准的窗口覆盖表格:
1 | 1,2 | 2,3 | 3 |
1,4 | 1,2,4,5 | 2,3,5,6 | 3,6 |
4,7 | 4,5,7,8 | 5,6,8,9 | 6,9 |
7 | 7,8 | 8,9 | 9 |
每个方格的数字,会覆盖它前面的数字。根据覆盖构建一个有向图。判断输入的数据所形成的有向图是否形成一个环,这就是拓扑排序里面判断是否有环的问题。
首先在输入之前,构建好标准覆盖。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int L[10][10];
int indegree[10];
int TopSort();
int main()
{
int i,j,t;
string cover[5][5];
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cover[i][j]+=j+1+i*3+'0';
cover[i][j+1]+=j+1+i*3+'0';
cover[i+1][j]+=j+1+i*3+'0';
cover[i+1][j+1]+=j+1+i*3+'0';
}
}
/**
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
string::iterator y;
for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y)
{
cout<<*y;
}
cout<<" ";
}
cout<<endl;
}
*/
string s;
while(cin>>s)
{
getchar();
if(s=="ENDOFINPUT") break;
memset(indegree,0,sizeof(indegree));
memset(L,0,sizeof(L));
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
char x;
scanf("%c",&x);
string::iterator y; //指向STRING的迭代器,其实和指针的概念是一样。
for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y)
{
if((*y)!=x&&L[x-'0'][(*y)-'0']==0)
{
L[x-'0'][(*y)-'0']=1;
indegree[(*y)-'0']++;
}
}
getchar();
}
}
cin>>s;
getchar();
/**
for(i=1; i<10; i++)
{
cout<<i<<":";
for(j=0; j<10; j++)
{
if(L[i][j]==1)
cout<<j<<" ";
}
cout<<endl;
}
cout<<"indegree:";
for(i=1; i<10; i++) cout<<indegree[i]<<" ";
cout<<endl;
*/
int flag=TopSort();
if(flag) cout<<"THESE WINDOWS ARE CLEAN"<<endl;
else cout<<"THESE WINDOWS ARE BROKEN"<<endl;
}
return 0;
}
int TopSort()
{
int i,j;
int n=9;
int sign=0;
while(n--)
{
sign=0;
for(i=1; i<10; i++)
{
if(indegree[i]==0) sign=i;
}
if(sign>0)
{
for(j=0; j<10; j++)
{
if(L[sign][j])
indegree[j]--;
}
indegree[sign]=-1;
}
else if(sign==0) return 0;
}
return 1;
}
POJ 2585.Window Pains 拓扑排序的更多相关文章
- 【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. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...
随机推荐
- CentOS 6.4 i386 版本安装 FastDFS、使用Nginx作为文件访问WEB服务器
安装环境:1. CentOS-6.4-i3862. FastDFS_v4.063. fastdfs-nginx-module_v1.154. Nginx-1.5.6(安装见此)5. libevent- ...
- CSS3基础
内容: 1.圆角 border-radius 2.阴影 text-shadow.box-shadow 3.渐变 linear.radial 4.rgba rgb+alpha opacity 5.tra ...
- html_table表格
## `table`表格 表格的常用标签 - `table`表格- `thead`表格头- `tbody`表格主体- `tfoot`表格尾- `th`元素定义表头单元格- `tr`定义表格行- `td ...
- leetcode29
class Solution { public int divide(int dividend, int divisor) { if (dividend == Integer.MIN_VALUE &a ...
- Find 和 Findstr
FIND 在文件中搜索文字字符串. FINDSTR 在文件中搜索字符串. findstr能用正则表达式,而find不能 dir c:|find /N /I /C "windows&q ...
- as3 区别中文 英文 数字
1)英文a-z是65-90,A-Z是97-112 2)数字是0-9是,48-57 3)上万的都是中文字符 var str:String = "hello world! 你好世界! 88!&q ...
- ABAP-动态编程
转载:http://www.cnblogs.com/jiangzhengjun/p/4293407.html 动态编程 动态的基本语法 多种不同的动态编程 动态字段 动态类型 指定结构.内表组件字段的 ...
- UI5-文档-4.5-Controllers
在这个步骤中,我们将文本替换为一个按钮,并在按钮被按下时显示“Hello World”消息.按钮的按下事件的处理是在视图的控制器中实现的. Preview A Say Hello button is ...
- Apache Hive 执行HQL语句报错 ( 10G )
# 故障描述: hive > , ) as uuid, count(distinct(request_body["uuid"])) as count from log_bft ...
- Apache Hive 存储方式、压缩格式
简介: Apache hive 存储方式跟压缩格式! 1.Text File hive> create external table tab_textfile ( host string com ...