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;
}

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

posted @ 2015-07-22 17:23  xryz  阅读(220)  评论(0编辑  收藏  举报