Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴力模拟,把完整的玻璃往下搬,发现存在不完整就是Broken,全部办完就是CLean,(附代码)

Posted by WilliamACM at 2012-08-23 02:39:21 on Problem 2585
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
int a[4][4];
char s[15];
bool check(int c)
{
    c--;
    int x=c/3,y=c%3;c++;
    int ma=0,oo=0;
    for(int i=x;i<=x+1;i++)
    for(int j=y;j<=y+1;j++)
    {
        if(a[i][j]==c) ma++;
        if(a[i][j]==0)oo++;
    }
    if(oo==4) return 0;
    if(oo+ma==4)
    {

        for(int i=x;i<=x+1;i++)
        for(int j=y;j<=y+1;j++) a[i][j]=0;
        return 1;
    }
    return 0;


}
void init()
{
    for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
    scanf("%d",&a[i][j]);
    while(1)
    {
        int go=0;
        for(int i=1;i<=9;i++)
        {
            if(check(i))
            go++;
        }
        if(go==0) break;
    }
    int ans=0;
    for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)ans+=a[i][j];


    printf("THESE WINDOWS ARE %s\n",ans?"BROKEN":"CLEAN");
}
int main()
{
   // freopen("in.txt","r",stdin);
    while(gets(s),strlen(s)<9)
    {
        init();
        gets(s);
        gets(s);
    }
//    cout << "Hello world!" << endl;
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator