Windows Pains poj 2585
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
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
题目大意 :题目中给出了几幅图,判断给出的矩阵能否有题目中的图片叠加而成。
题解:该题难在构图与题意上。如果能够由每个图片叠加而成那么一定会有个先后。也就是说,一定能用拓扑排序将其排列好。如果拓扑排序没有成功排出,输出 THESE WINDOWS ARE BROKEN。否则输出THESE WINDOWS ARE CLEAN
还有一个难点就是在构图上。我们只需要记录每个数字的左上角的坐标,然后进行搜索见图,即判断该数字本身位置有没有被覆盖,右边下边以及右下角有没有被覆盖。被覆盖的话,就用邻接矩阵标记为1.并记录节点的 入度
//判断所有位置的覆盖情况
//如果a覆盖b 则构造一条边edge[b][a]=1 最后得到一个图
//这个图一定是无环的 如果有环则表示a覆盖b b又覆盖a
//即显示不正常
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int N=1E5+;
int arr[][]; int arr2[][]={{,}, {,},{,},{,}, {,},{,},{,}, {,},{,},{,} };// 每个区域的左上角
int dir[][]={{,},{,},{,},{,}};//对应四个方向 本身,右边,下边,还有右下角 int map[][];
int in[N];
int main(){
string a;
while(cin>>a&&a!="ENDOFINPUT"){ memset(in,,sizeof(in));
memset(arr,,sizeof(arr));
memset(map,,sizeof(map)); for(int i=;i<=;i++)
for(int j=;j<=;j++){
scanf("%d",&arr[i][j]);
} string b;
cin>>b;
//建图
for(int i=;i<=;i++){
for(int j=;j<;j++){
int dx=arr2[i][]+dir[j][];
int dy=arr2[i][]+dir[j][];
int dz=arr[dx][dy];
if(dz!=i&&map[dz][i]==){
map[dz][i]=;
in[i]++;
}
}
} queue<int >que;
for(int i=;i<=;i++){
if(in[i]==){
que.push(i);
}
} int sum=;
while(que.size()){
int xx=que.front();
que.pop();
sum++;
for(int i=;i<=;i++){
if(map[xx][i]==){
in[i]--;
if(in[i]==){
que.push(i);
}
}
}
} if(sum==) puts("THESE WINDOWS ARE CLEAN");
else puts("THESE WINDOWS ARE BROKEN");
}
return ;
}
Windows Pains poj 2585的更多相关文章
- poj 2585 Window Pains 解题报告
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2027 Accepted: 1025 Desc ...
- poj 2585 Window Pains 暴力枚举排列
题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...
- POJ 2585.Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1888 Accepted: 944 Descr ...
- POJ 2585 Window Pains 题解
链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上 ...
- POJ 2585:Window Pains(拓扑排序)
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2524 Accepted: 1284 Desc ...
- zoj 2193 poj 2585 Window Pains
拓扑排序. 深刻体会:ACM比赛的精髓之处不在于学了某个算法或数据结构,而在于知道这个知识点但不知道这个问题可以用这个知识去解决!一看题目,根本想不到是拓扑排序.T_T...... #include& ...
- 【POJ 2585】Window Pains 拓扑排序
Description . . . and so on . . . Unfortunately, Boudreaux's computer is very unreliable and crashes ...
- Window Pains(poj 2585)
题意: 一个屏幕要同时打开9个窗口,每个窗口是2*2的矩阵,整个屏幕大小是9*9,每个窗口位置固定. 但是是否被激活(即完整显示出来)不确定. 给定屏幕状态,问是否可以实现显示. 分析:拓扑排序,把完 ...
- [POJ 2585] Window Pains 拓朴排序
题意:你现在有9个2*2的窗口在4*4的屏幕上面,由于这9这小窗口叠放顺序不固定,所以在4*4屏幕上有些窗口只会露出来一部分. 如果电脑坏了的话,那么那个屏幕上的各小窗口叠放会出现错误.你的任务就是判 ...
随机推荐
- ThreadPoolTaskExecutor 中 corePoolSize vs. maxPoolSize
1. 概览 Spring中的 ThreadPoolTaskExecutor 是一个 JavaBean ,提供围绕java.util.concurrent.ThreadPoolExecutor 的抽象实 ...
- 写爬虫爬了3w条职位数据,看看当前招聘形势 | 开源
最近有不少程序员又开始找工作了,为了了解目前技术类各职位的数量.薪资.招聘公司.岗位职责及要求,我爬取了拉勾网北上广深4个城市的招聘数据,共3w条.职位包括:人工智能(AI).大数据.数据分析.后端( ...
- 强化学习之七:Visualizing an Agent’s Thoughts and Actions
本文是对Arthur Juliani在Medium平台发布的强化学习系列教程的个人中文翻译,该翻译是基于个人分享知识的目的进行的,欢迎交流!(This article is my personal t ...
- 在Fedora中安装OpenCV-Python | 二
目标 在本教程中 我们将学习在你的Fedora系统中设置OpenCV-Python.针对Fedora 18(64位)和Fedora 19(32位)进行以下步骤. 介绍 可以通过两种方式在Fedora中 ...
- NLPer入门指南 | 完美第一步
介绍 你对互联网上的大量文本数据着迷吗?你是否正在寻找处理这些文本数据的方法,但不确定从哪里开始?毕竟,机器识别的是数字,而不是我们语言中的字母.在机器学习中,这可能是一个棘手的问题. 那么,我们如何 ...
- HDU - 1999 不可摸数,快速求因子和
题意:定义s[m]为m内的因子的和,给定一个n,判断是否有s[m]==n,若没有,则是不可摸数. 思路:首先要打表求出s[m]的值,标记这些出现过的值. 打表求因子和: for(int i=1;i&l ...
- 一夜搞懂 | JVM 类加载机制
前言 本文已经收录到我的Github个人博客,欢迎大佬们光临寒舍: 我的GIthub博客 学习导图 一.为什么要学习类加载机制? 今天想跟大家唠嗑唠嗑Java的类加载机制,这是Java的一个很重要的创 ...
- 编译原理:DFA最小化,语法分析初步
1.将DFA最小化:教材P65 第9题 解析: 2.构造以下文法相应的最小的DFA S→ 0A|1B A→ 1S|1 B→0S|0 解析: S→ 0A|1B →S → 0(1S|1)|1(0S|0 ...
- 模板字符串原理,原生js实现字符串模板
在使用模板字符串的时候使用的是 '{{}}'形式进行书写,本文则向各位解密这么写的原因 初体验正则 首先要先明白正则表达式中exec的使用 例如: let str = 'axu1997@qq.com' ...
- nginx代理图片上传以及访问
nginx代理图片上传 首先需要利用nginx代理图片访问参考 https://www.cnblogs.com/TJ21/p/12609017.html 编写接受文件的controller @Post ...