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. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...
随机推荐
- 并发工具类(五) Phaser类
前言 JDK中为了处理线程之间的同步问题,除了提供锁机制之外,还提供了几个非常有用的并发工具类:CountDownLatch.CyclicBarrier.Semphore.Exchanger.Ph ...
- MS SQL Server 定时任务实现自动备份
SQL Server Express 版本是没有SQL 代理服务的,从而导致不能使用SQL Server的定时自动备份功能.真心感觉这就是一个坑,虽然Express是学习的版本,但是精简的也太多了.另 ...
- 自定义BeanUtils
package com.icil.booking.service.util; import java.math.BigDecimal; import java.text.ParseException; ...
- leetcode942
public class Solution { public int[] DiStringMatch(string S) { var len = S.Length; ; var max = len; ...
- Simple2D-26 Simple2D 最后的工作,开发结束
开始的时候打算将 Simple2D 做成一个库的,但现在没有那个功夫了. 要渲染顶点数据,就必须将渲染函数放置到 glClear( ) 函数和 SwapBuffers( ) 函数之间,但又不希望开发时 ...
- UI5-文档-4.10-Descriptor for Applications
所有特定于应用程序的配置设置现在将进一步放在一个名为manifest的单独描述符文件中.json.这清楚地将应用程序编码从配置设置中分离出来,使我们的应用程序更加灵活.例如,所有SAP Fiori应用 ...
- UI5-文档-4.5-Controllers
在这个步骤中,我们将文本替换为一个按钮,并在按钮被按下时显示“Hello World”消息.按钮的按下事件的处理是在视图的控制器中实现的. Preview A Say Hello button is ...
- Mybatis知识(4)
1.当实体类中的属性名和表中的字段名不一样 解决办法①: 通过在查询的sql语句中定义字段名的别名,让字段名的别名和实体类的属性名一致 <select id=”selectorder” para ...
- 两个关于URL解析的例子
例一: /* 解析URL查寻串中的name=value参数对 将name=value对存储在对象属性中,并返回对象 alert(getQuery().name) */ function getQuer ...
- Gviz
1) Introduction 为了理解基因组数据,通常旨在在基因组浏览器中绘制这样的数据,以及各种基因组注释特征,例如基因或转录物模型,CpG岛,重复区域等.这些功能可以从ENSEMBL或UCSC等 ...