zoj 2193 Window Pains

#include<bits/stdc++.h>
using namespace std;
string cover[4][4];

int main()
{
    int i,j,k,mp[4][4],use[10],sum,flag,cnt[10],g[10][10];
    char s[100];
    for(i=0;i<4;i++)
        for(j=0;j<4;j++)
    {
        cover[i][j].erase();
    }
    for(k=1;k<=9;k++)
    {
        i=(k-1)/3;
        j=(k-1)%3;
        cover[i][j]+=char(k+‘0‘);
        cover[i][j+1]+=char(k+‘0‘);
        cover[i+1][j]+=char(k+‘0‘);
        cover[i+1][j+1]+=char(k+‘0‘);
    }
    while(~scanf("%s",s))
    {
        if(strcmp(s,"ENDOFINPUT")==0) break;
        sum=0;
        memset(cnt,0,sizeof(cnt));
        memset(g,0,sizeof(g));
        memset(use,0,sizeof(use));
        for(i=0;i<4;i++)
            for(j=0;j<4;j++)
        {
            scanf("%d",&mp[i][j]);
            if(use[mp[i][j]]==0)
            {
                sum++;
                use[mp[i][j]]=1;
            }
        }

        for(i=0;i<4;i++)
            for(j=0;j<4;j++)
                for(k=0;k<cover[i][j].size();k++)
                {
                    if(!g[mp[i][j]][cover[i][j][k]-‘0‘]
                       &&(mp[i][j]!=cover[i][j][k]-‘0‘))
                    {
                        g[mp[i][j]][cover[i][j][k]-‘0‘]=1;
                        cnt[cover[i][j][k]-‘0‘]++;
                    }
                }

        for(flag=1,k=0;k<sum;k++)
        {
            i=1;
            while(!use[i]||(i<=9&&cnt[i]>0)) i++;
            if(i>9) {flag=0;break;}
            use[i]=0;
            for(j=1;j<=9;j++)
            {
                if(use[j]&&g[i][j]) cnt[j]--;
            }
        }

        if(flag) printf("THESE WINDOWS ARE CLEAN\n");
        else printf("THESE WINDOWS ARE BROKEN\n");

        scanf("%s",s);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-01 17:30:56

zoj 2193 Window Pains的相关文章

poj 2585 Window Pains 解题报告

Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2027   Accepted: 1025 Description Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one application at a time, he

poj 2585 Window Pains(拓扑排序)(经典)(困难)

Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1756   Accepted: 881 Description Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one application at a time, he u

POJ 2585.Window Pains

Window Pains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1888   Accepted: 944 Description Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one application at a time, he u

POJ 2585 Window Pains(拓扑排序&#183;窗口覆盖)

题意  有一个4*4的显示器  有9个程序  每个程序占2*2个格子  他们的位置如图所示  当你运行某个程序时  这个程序就会显示在顶层覆盖其它的程序  给你某个时刻显示器的截图  判断此时电脑是否死机了(出现了不合法的覆盖关系) 拓扑排序的应用  关键是建图  当一个程序A的区域上有其它程序B时  说明A是在B之前运行的  那么我们可以建立一个A<B的拓扑关系  最后判断是否有环就行了  个人认为下标换为0操作起来比较方便  所以都还为了0 #include <cstdio> #in

zoj 2193 poj 2585 Window Pains

拓扑排序. 深刻体会:ACM比赛的精髓之处不在于学了某个算法或数据结构,而在于知道这个知识点但不知道这个问题可以用这个知识去解决!一看题目,根本想不到是拓扑排序.T_T...... #include<stdio.h> #include<string.h> #include<math.h> #include<vector> #include<algorithm> using namespace std; int mapp[50][50]; char

Window Pains

http://poj.org/problem?id=2585 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1614   Accepted: 806 Description Boudreaux likes to multitask, especially when it comes to using his computer. Never satisfied with just running one applicati

Window Pains POJ 2585

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 ov

POJ 2585 Window Pains 题解

链接:http://poj.org/problem?id=2585 题意: 某个人有一个屏幕大小为4*4的电脑,他很喜欢打开窗口,他肯定打开9个窗口,每个窗口大小2*2.并且每个窗口肯定在固定的位置上(见题目上的图),某些窗口可以覆盖另一些窗口(可以脑补).询问给出的电脑屏幕是否是合法的. 分析: 可以预先处理出每个格子应该有哪几个窗口在这上面,将最上面的窗口与其他窗口连边,得到一张图,用拓扑判环,因为这道题太简单了,所以我就写这么短的题解. 代码: 1 #include<iostream>

POJ 2585 Window Pains 拓扑排序

poj2585 题意: 有一块4X4的屏幕   屏幕中共有9块固定位置的2X2窗口(相互覆盖)  问窗口是否全部显示正常 题解: 判断所有位置的覆盖情况 如果a覆盖b 则构造一条边edge[b][a]=1    最后得到一个图 这个图一定是无环的   如果有环则表示a覆盖b   b又覆盖a 即显示不正常 代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; int m