Window Pains

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2524   Accepted: 1284

Description

Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one application at a time, he usually runs nine applications, each in its own window. Due to limited screen real estate, he overlaps these windows and brings whatever window he currently needs to work with to the foreground. If his screen were a 4 x 4 grid of squares, each of Boudreaux's windows would be represented by the following 2 x 2 windows:

1 1 . .
1 1 . .
. . . .
. . . .
. 2 2 .
. 2 2 .
. . . .
. . . .
. . 3 3
. . 3 3
. . . .
. . . .
. . . .
4 4 . .
4 4 . .
. . . .
. . . .
. 5 5 .
. 5 5 .
. . . .
. . . .
. . 6 6
. . 6 6
. . . .
. . . .
. . . .
7 7 . .
7 7 . .
. . . .
. . . .
. 8 8 .
. 8 8 .
. . . .
. . . .
. . 9 9
. . 9 9

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:

1 2 2 ?
1 2 2 ?
? ? ? ?
? ? ? ?
If window 4 were then brought to the foreground:
1 2 2 ?
4 4 2 ?
4 4 ? ?
? ? ? ?

. . . 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

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. 

A single data set has 3 components:

  1. Start line - A single line: 

    START
  2. 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.
  3. 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

For each data set, there will be exactly one line of output. If there exists a sequence of bringing windows to the foreground that would result in the graphical representation of the windows on Boudreaux's screen, the output will be a single line with the statement: 

THESE WINDOWS ARE CLEAN 

Otherwise, the output will be a single line with the statement: 

THESE WINDOWS ARE BROKEN

Sample Input

  1. START
  2. 1 2 3 3
  3. 4 5 6 6
  4. 7 8 9 9
  5. 7 8 9 9
  6. END
  7. START
  8. 1 1 3 3
  9. 4 1 3 3
  10. 7 7 9 9
  11. 7 7 9 9
  12. END
  13. ENDOFINPUT

Sample Output

  1. THESE WINDOWS ARE CLEAN
  2. THESE WINDOWS ARE BROKEN

题意

有9个程序窗口在4*4的矩阵中,每个程序窗口占用2*2矩阵的空间,编号为1~9。如下图(画的有点乱,应该能看懂)

在这些程序窗口中存在相互覆盖的关系,给出9*9的数字矩阵,每个数字表示程序窗口。问这样的相互覆盖关系是否合理

思路

拓扑排序模板题。但是建图太难了T_T,建好图进行拓扑排序,判断排序之后还有没有相连的边就行了

样例中的建好的图如下图(图片来自http://www.cnblogs.com/pony1993/archive/2012/08/16/2641904.html

AC代码

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <limits.h>
  7. #include <map>
  8. #include <stack>
  9. #include <queue>
  10. #include <vector>
  11. #include <set>
  12. #include <string>
  13. #define ll long long
  14. #define ms(a) memset(a,0,sizeof(a))
  15. #define pi acos(-1.0)
  16. #define INF 0x3f3f3f3f
  17. const double E=exp(1);
  18. const int maxn=1e3+10;
  19. using namespace std;
  20. int a[maxn][maxn];
  21. int vis[maxn];
  22. int b[maxn][maxn];
  23. void toposort()
  24. {
  25. for(int i=1;i<=9;i++)
  26. {
  27. for(int j=1;j<=9;j++)
  28. {
  29. if(vis[j]==0)
  30. {
  31. vis[j]--;
  32. for(int k=1;k<=9;k++)
  33. {
  34. if(b[j][k])
  35. {
  36. b[j][k]--;
  37. vis[k]--;
  38. }
  39. }
  40. break;
  41. }
  42. }
  43. }
  44. }
  45. int main(int argc, char const *argv[])
  46. {
  47. ios::sync_with_stdio(false);
  48. string str;
  49. string st;
  50. while(cin>>str)
  51. {
  52. ms(vis);
  53. ms(a);
  54. ms(b);
  55. if(str=="ENDOFINPUT")
  56. break;
  57. for(int i=1;i<=4;i++)
  58. for(int j=1;j<=4;j++)
  59. cin>>a[i][j];
  60. cin>>st;
  61. for(int i=1;i<=3;i++)
  62. {
  63. for(int j=1;j<=3;j++)
  64. {
  65. for(int ii=0;ii<2;ii++)
  66. {
  67. for(int jj=0;jj<2;jj++)
  68. {
  69. if(a[i+ii][j+jj]==j+(i-1)*3)
  70. continue;
  71. else if(b[a[i+ii][j+jj]][j+(i-1)*3]==0)
  72. {
  73. b[a[i+ii][j+jj]][j+(i-1)*3]=1;
  74. vis[j+(i-1)*3]++;
  75. }
  76. }
  77. }
  78. }
  79. }
  80. toposort();
  81. int flag=0;
  82. for(int i=1;i<=9;i++)
  83. {
  84. for(int j=1;j<=9;j++)
  85. {
  86. flag+=b[i][j];
  87. }
  88. }
  89. if(flag)
  90. cout<<"THESE WINDOWS ARE BROKEN"<<endl;
  91. else
  92. cout<<"THESE WINDOWS ARE CLEAN"<<endl;
  93. }
  94. return 0;
  95. }

POJ 2585:Window Pains(拓扑排序)的更多相关文章

  1. POJ 2585.Window Pains 拓扑排序

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1888   Accepted: 944 Descr ...

  2. 【POJ 2585】Window Pains 拓扑排序

    Description . . . and so on . . . Unfortunately, Boudreaux's computer is very unreliable and crashes ...

  3. [POJ 2585] Window Pains 拓朴排序

    题意:你现在有9个2*2的窗口在4*4的屏幕上面,由于这9这小窗口叠放顺序不固定,所以在4*4屏幕上有些窗口只会露出来一部分. 如果电脑坏了的话,那么那个屏幕上的各小窗口叠放会出现错误.你的任务就是判 ...

  4. poj 2585 Window Pains 解题报告

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2027   Accepted: 1025 Desc ...

  5. POJ2585 Window Pains 拓扑排序

    Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1843   Accepted: 919 Descr ...

  6. zoj 2193 poj 2585 Window Pains

    拓扑排序. 深刻体会:ACM比赛的精髓之处不在于学了某个算法或数据结构,而在于知道这个知识点但不知道这个问题可以用这个知识去解决!一看题目,根本想不到是拓扑排序.T_T...... #include& ...

  7. poj 2585 Window Pains 暴力枚举排列

    题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...

  8. POJ 2585 Window Pains 题解

    链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上 ...

  9. [poj2585]Window Pains_拓扑排序

    Window Pains poj-2585 题目大意:给出一个4*4的方格表,由9种数字组成.其中,每一种数字只会出现在特定的位置,后出现的数字会覆盖之前在当前方格表内出现的.询问当前给出的方格表是否 ...

  10. POJ 2367 (裸拓扑排序)

    http://poj.org/problem?id=2367 题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...

随机推荐

  1. Spring生态顶级项目说明

    1.Spring IO platform 说明:用于系统部署,是可集成的,构建现代化应用的版本平台 2.Spring Boot 说明:旨在简化创建产品级的 Spring 应用和服务,简化了配置文件,使 ...

  2. Chrome开发者工具之JavaScript内存分析(转)

    尽管JavaScript使用垃圾回收进行自动内存管理,但有效的(effective)内存管理依然很重要.在这篇文章中我们将探讨分析JavaScript web应用中的内存问题.在学习有关特性时请确保尝 ...

  3. 一个纯净的webpack4+angular5脚手架

    该篇主要是结合刚发布不久的webpack4,搭建一个非cli的angular5的脚手架demo,主要分为以下几个方面阐述下脚手架结构: # 脚手架基础架构(根据angular5的新规范) /** * ...

  4. C#一套简单的单例系统

    单例基类 public class CSingletonBase<TYPE> { public static TYPE Singleton { get { return m_singlet ...

  5. 拓扑排序 Topological Sort

    2018-05-02 16:26:07 在计算机科学领域,有向图的拓扑排序或拓扑排序是其顶点的线性排序,使得对于从顶点u到顶点v的每个有向边uv,u在排序中都在v前.例如,图形的顶点可以表示要执行的任 ...

  6. Silverlight自定义控件系列 – TreeView (4) 缩进

    接下来是缩进,没有缩进的Tree怎么看都不顺眼. 首先,定义节点深度Depth(注:回叫方法暂没有代码,以后要用到): 1: /// <summary> 2: /// Using a De ...

  7. hdu-4417-主席树+离线

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. JavaScript权威指南(第6版)(中文版)笔记

      JavaScript权威指南(第6版)(中文版)笔记      

  9. 51nod1615

    题解: 首先,当1+2+...+n=x时,答案就是n 如果1+2+...+n不会等于x,那么找一个最小的n,让1+2+....+n>x并且(1+2+.....+n-x)%2=0 代码: #inc ...

  10. [转载]request.getServletPath()方法

    假定你的web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果 ...