Window Pains
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:
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:
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 Source |
题比较难读,然后窗口处理这块很有意思,感觉没有接触过很难想到方法。
窗口具体怎么处理可以看代码里的注释。主要就是把所有窗口走一遍,和他位置不同的表示被覆盖了。题意有时间了补一下吧……现在不太想翻译_(:з」∠)_
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int map[15][15],G[15],screen[5][5];
int dis[4][2]={{0,0},{1,0},{0,1},{1,1}};//窗口的范围
int local[10][2]={{-1,-1},{0,0},{0,1},{0,2},{1,0},{1,1},{1,2},{2,0},{2,1},{2,2}};//每个窗口右上角点的坐标
int top()
{
int i,j,tmp,flag;
for(i=1;i<=9;i++)
{
flag=0;
for(j=1;j<=9;j++)
if(G[j]==0)
{
flag=1;
tmp=j;
break;
}
if(!flag) return 0;
G[tmp]=-1;
for(j=1;j<=9;j++)
if(map[tmp][j])
G[j]--;
}
return 1;
}
int main()
{
char ch[15];
int i,j;
while(scanf("%s",ch)&&strcmp(ch,"ENDOFINPUT")!=0)
{
memset(map,0,sizeof(map));
memset(G,0,sizeof(G));
for(i=0;i<4;i++)
for(j=0;j<4;j++)
scanf("%d",&screen[i][j]);
scanf("%s",ch);
for(i=1;i<=9;i++)
{
for(j=0;j<4;j++)
{
int x=local[i][0]+dis[j][0];//i窗口的坐标
int y=local[i][1]+dis[j][1];
int z=screen[x][y];//这个坐标在屏幕里的实际窗口
if(z!=i&&!map[i][z])//不同说明覆盖
{
map[i][z]=1;
G[z]++;
}
}
}
if(top())
printf("THESE WINDOWS ARE CLEAN\n");
else
printf("THESE WINDOWS ARE BROKEN\n");
}
return 0;
}