专栏首页一Wa哇一天POJ-2585-Window Pains

POJ-2585-Window Pains

POJ-2585-Window Pains

Window PainsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2915 Accepted: 1461

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:

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 

不得不说Poj的题就是难,想了好久但是可算有点思路了,结果交了一发,直接Wa,这谁受得了呀,后来找了好几篇博客才看明白,因为每个方格都会有一组固定的几个数,我们事先将每个方格里面的数打标打出来,然后在输入图形的时候进行处理,输入的谁,谁就就大于其他值,例如:(3,3)这个位置,可能出现的数字是:5,6,8,9;如果在输入的时候,输入的是8,那就在构建拓排图的时候让8>6,8>6,8>9;遇到自身的话就跳过,这样构好图后就按照平常的拓排进行跑就行了,只有又环的出现那么久不满足情况,另外要注意去重,应为方格的情况可能冲突所以要注意去重;

#include<iostream>
#include<queue>
#include<vector>
#include<string.h>
#include<string>
#include<set>
using namespace std;

typedef pair<int,int> pa;
vector<int>v[100];
int mp[5][5];
string s;
int in[20];
set<pa>se;
int mmp[4][4][6]={                 //前两个4表示的是位置,第几行第几列,最后一个6表示里面可能有的数字,                                                
{{1,1},{2,1,2},{2,2,3},{1,3}}    //注意我的每一个开始的数字是表示这个位置可能有几个数字
,{{2,1,4},{4,1,2,4,5},{4,2,3,5,6},{2,3,6}}//这样的话方便以后的构图
,{{2,4,7},{4,4,5,7,8},{4,5,6,8,9},{2,6,9}},
{{1,7},{2,7,8},{2,8,9},{1,9}}
};
void gt(int x,int y)//大概的构造图形,把每个点的大小关系都放进set,进行去重;
{
    for(int i=1;i<=mmp[x][y][0];i++)
    {
        int xx=mmp[x][y][i];
        if(xx!=mp[x][y])//如果相等就不放进去
        {
            se.insert(make_pair(xx,mp[x][y]));
        }
    }
}

int main()
{
    while(cin>>s)
    {
        if(s=="ENDOFINPUT") break;    
    //    数据初始化,很重要!!!
        se.clear();
        for(int i=0;i<10;i++) v[i].clear();
        memset(in, 0,sizeof in);

        for(int i=0;i<4;i++)
        {
            for(int j=0;j<4;j++)
            {
                cin>>mp[i][j];
                gt(i,j);//进行大小关系的确定
            }
        }
        cin>>s;

        pa p;
        set<pa>::iterator it;//从set里面取数,然后开始正式的构建拓排有向图
        for(it=se.begin();it!=se.end();it++)//
        {
            p=*it;
            int x=p.first ;
            int y=p.second ;
            v[x].push_back(y);
            in[y]++; //入度加一
        }
    //查找入度为零的节点,从入度为零的节点开始删除
        queue<int>q;
        for(int i=1;i<10;i++)
        {
            if(!in[i]) q.push(i);  
        }
        int k=9;
    //拓排删除节点
        while(!q.empty() )
        {
            int x=q.front() ;q.pop() ;
            k--;
            for(int i=0;i<v[x].size() ;i++)
            {
                in[v[x][i]]--;//都一个节点度数减少一
                if(!in[v[x][i]]) q.push(v[x][i]); 
            }
        }
//如果k最后不等0,说明还有节点没被删除,也就是说形成了环
        if(k) cout<<"THESE WINDOWS ARE BROKEN"<<endl;
        else cout<<"THESE WINDOWS ARE CLEAN"<<endl;
    }
    return 0;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 2019-2020 ICPC Southeastern European Regional Programming Contest (SEERC 2019)-G.Projection

    Everybody knows that you are a TensorFlow fan. Therefore, you’ve been challenged...

    某些人
  • C. NEKO's Maze Game

    time limit per test:1.5 seconds memory limit per test:256 megabytes inputstandar...

    某些人
  • 并查集

    POJ 的题真的是对小白选手的一个大的磨炼了,看了好久才明白题意,然后发现还是不会写题意就是给你一个数n,然后又n次操作,每次操作有两种情况如果第一个字符是 M...

    某些人
  • POJ 1012 Joseph

    Joseph Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53862 ...

    Angel_Kitty
  • hdu---(1800)Flying to the Mars(trie树)

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768...

    Gxjun
  • ZOJ 3204 Connect them

    Connect them ---- Time Limit: 1 Second      Memory Limit: 32768 KB ---- You have...

    ShenduCC
  • Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)

    A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 m...

    Angel_Kitty
  • 周练19.11.03/10

    它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。

    AngelNH
  • US oil prices turn negative as demand dries up

    The price of US oil has turned negative for the first time in history.

    仇诺伊
  • POJ-1276-Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions:...

    ShenduCC

扫码关注云+社区

领取腾讯云代金券