三沣开发知识 购物 网址 游戏 小说 歌词 地图 快照 开发 股票 美女 新闻 笑话 | 汉字 软件 日历 阅读 下载 图书馆 编程 租车 短信 China
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
vbs/VBScript DOS/BAT hta htc python perl 游戏相关 VBA 远程脚本 ColdFusion ruby专题
autoit seraphzone PowerShell linux shell Lua Golang Erlang 其它教程 CSS/HTML/Xhtml
html5 CSS XML/XSLT Dreamweaver教程 经验交流 开发者乐园 Android开发资料
站长资讯 .NET新手 ASP.NET C# WinForm Silverlight WCF CLR WPF XNA VisualStudio ASP.NET-MVC .NET控件开发 EntityFramework WinRT-Metro Java C++ PHP Delphi Python Ruby C语言 Erlang Go Swift Scala R语言 Verilog 其它语言 架构设计 面向对象 设计模式 领域驱动 Html-Css JavaScript jQuery HTML5 SharePoint GIS技术 SAP OracleERP DynamicsCRM K2 BPM 信息安全 企业信息 Android开发 iOS开发 WindowsPhone WindowsMobile 其他手机 敏捷开发 项目管理 软件工程 SQLServer Oracle MySQL NoSQL 其它数据库 Windows7 WindowsServer Linux
  IT知识库 -> C++ -> POJ2585 Window Pains 拓扑排序 -> 正文阅读
 

[C++]POJ2585 Window Pains 拓扑排序

POJ2585 Window Pains 拓扑排序 Window Pains
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1843   Accepted: 919
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: 
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
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

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



题意:
有一个拥有4×4网格的显示屏,有9个2×2的程序窗口,把一个窗口调到最前时,它的所有方格中的数字都位于最前,覆盖共用的方格。按照不同的顺序将窗口调到最前,但是计算机很不稳定,经常崩溃。输入的窗口的状态,判断是否能出现这样的窗口状态。可以的话说明计算机没有崩溃,输出“THESE WINDOWS ARE CLEAN”,否则输出“THESE WINDOWS ARE BROKEN”。
每组数据已“START”开始,已“END”结束。中间是方格数字显现的状态。如果输入“ENDOFINPUT”就结束输入。



计算机每个方格中拥有的数字:

 1  1,2,  2,3, 3 1,4  1,2,4,5 2,3,5,6  3,6  4  4,5  5,6,8,9  6,9  7  7,8  8,9  9
那么相应方格中显示出来的数字就覆盖了相应方格中那些其他的数字。覆盖之间建立一条边,最终形成的图是否正常。
这就是一个拓扑排序问题,图中不能有环,有环说明不合理,也就是计算机崩溃。无环说明图合理。


  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 using namespace std;
  5 int L[10][10];
  6 int indegree[10];
  7 int TopSort();
  8 int main()
  9 {
 10     int i,j,t;
 11     string cover[5][5];
 12     for(i=0; i<3; i++)
 13     {
 14         for(j=0; j<3; j++)
 15         {
 16             cover[i][j]+=j+1+i*3+'0';
 17             cover[i][j+1]+=j+1+i*3+'0';
 18             cover[i+1][j]+=j+1+i*3+'0';
 19             cover[i+1][j+1]+=j+1+i*3+'0';
 20         }
 21     }
 22     /**
 23     for(i=0; i<4; i++)
 24     {
 25         for(j=0; j<4; j++)
 26         {
 27             string::iterator y;
 28             for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y)
 29             {
 30                 cout<<*y;
 31             }
 32             cout<<" ";
 33         }
 34         cout<<endl;
 35     }
 36     */
 37     string s;
 38     while(cin>>s)
 39     {
 40         getchar();
 41         if(s=="ENDOFINPUT") break;
 42         memset(indegree,0,sizeof(indegree));
 43         memset(L,0,sizeof(L));
 44         for(i=0; i<4; i++)
 45         {
 46             for(j=0; j<4; j++)
 47             {
 48                 char x;
 49                 scanf("%c",&x);
 50                 string::iterator y;
 51                 for (y=cover[i][j].begin(); y!=cover[i][j].end(); ++y)
 52                 {
 53                     if((*y)!=x&&L[x-'0'][(*y)-'0']==0)
 54                     {
 55                         L[x-'0'][(*y)-'0']=1;
 56                         indegree[(*y)-'0']++;
 57                     }
 58                 }
 59                 getchar();
 60             }
 61         }
 62         cin>>s;
 63         getchar();
 64         /**
 65         for(i=1; i<10; i++)
 66         {
 67             cout<<i<<":";
 68             for(j=0; j<10; j++)
 69             {
 70                 if(L[i][j]==1)
 71                     cout<<j<<" ";
 72             }
 73             cout<<endl;
 74         }
 75         cout<<"indegree:";
 76         for(i=1; i<10; i++) cout<<indegree[i]<<" ";
 77         cout<<endl;
 78         */
 79         int flag=TopSort();
 80         if(flag) cout<<"THESE WINDOWS ARE CLEAN"<<endl;
 81         else cout<<"THESE WINDOWS ARE BROKEN"<<endl;
 82     }
 83     return 0;
 84 }
 85 int TopSort()
 86 {
 87     int i,j;
 88     int n=9;
 89     int sign=0;
 90     while(n--)
 91     {
 92         sign=0;
 93         for(i=1; i<10; i++)
 94         {
 95             if(indegree[i]==0) sign=i;
 96         }
 97         if(sign>0)
 98         {
 99             for(j=0; j<10; j++)
100             {
101                 if(L[sign][j])
102                     indegree[j]--;
103             }
104             indegree[sign]=-1;
105         }
106         else if(sign==0) return 0;
107     }
108     return 1;
109 }

View Code
  C++ 最新文章
关于poin与references
019:别叫,这个大整数已经很简化了!
c++智能指针详解
BZOJ1269: [AHOI2006]文本编辑器editor
洛谷P3835 【模板】可持久化平衡树
洛谷P2925 [USACO08DEC]干草出售Hay For Sa
C++中枚举定义运算符
1044. Shopping in Mars (25)
Win10或Win8下ObjectARX2015 Wizard向导创建
CF 277E Binary Tree on Plane (拆点 + 费
上一篇文章      下一篇文章      查看所有文章
加:2015-11-21 14:21:58  更:2017-05-15 12:49:37 
 
技术频道: 站长资讯 .NET新手区 ASP.NET C# WinForm Silverlight WCF CLR WPF XNA Visual Studio ASP.NET MVC .NET控件开发 Entity Framework WinRT/Metro Java C++ PHP Delphi Python Ruby C语言 Erlang Go Swift Scala R语言 Verilog 其它语言 架构设计 面向对象 设计模式 领域驱动设计 Html/Css JavaScript jQuery HTML5 SharePoint GIS技术 SAP Oracle ERP Dynamics CRM K2 BPM 信息安全 企业信息化其他 Android开发 iOS开发 Windows Phone Windows Mobile 其他手机开发 敏捷开发 项目与团队管理 软件工程其他 SQL Server Oracle MySQL NoSQL 其它数据库 Windows 7 Windows Server Linux
脚本语言: vbs/VBScript DOS/BAT hta htc python perl 游戏相关 VBA 远程脚本 ColdFusion ruby专题 autoit seraphzone PowerShell linux shell Lua Golang Erlang 其它教程
网站开发: CSS/HTML/Xhtml html5 CSS XML/XSLT Dreamweaver教程 经验交流 开发者乐园 Android开发资料
360图书馆 软件开发资料 文字转语音 购物精选 软件下载 美食菜谱 新闻资讯 电影视频 小游戏 Chinese Culture 股票 租车
生肖星座 三丰软件 视频 开发 短信 中国文化 网文精选 搜图网 美图 阅读网 多播 租车 短信 看图 日历 万年历 2018年2日历
2018-2-19 16:13:48
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT知识库