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

Re:为什么是wa 有高人能指点一下吗

Posted by SJY021210 at 2016-08-26 13:56:55 on Problem 2386
In Reply To:为什么是wa 有高人能指点一下吗 Posted by:00448322 at 2005-04-25 21:21:59
#include<cstdio>
using namespace std;

int a[1000][2];
int b[1000][2];
bool z[101][101]={false};

int main()
{
    int i,j,m,n,l,h,t,x,y,k;
    char ch;

    scanf("%d%d",&n,&m);

    k=0;

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            scanf("%c",&ch);

            if(ch=='.')
            {
                z[i][j]=true;
            }
            else
            {
                z[i][j]=false;
                a[k][0]=i;
                a[k][1]=j;
                k++;
            }

        }

    }

    l=0;
    i=0;

    while(i<k)
    {
        while(i<k&&z[a[i][0]][a[i][1]])
        {
            i++;
        }
        if(i==k)
        {
            break;
        }

        x=a[i][0];
        y=a[i][1];
        h=0;
        t=1;
        b[h][0]=x;
        b[h][1]=y;

        while(h<t)
        {
            x=b[h][0];
            y=b[h][1];
            h++;

            if(x+1<n&&!z[x+1][y])
            {
                b[t][0]=x+1;
                b[t][1]=y;
                t++;
                z[x+1][y]=true;
            }

            if(y+1<m&&!z[x][y+1])
            {
                b[t][0]=x;
                b[t][1]=y+1;
                t++;
                z[x][y+1]=true;
            }

            if(x>0&&!z[x-1][y])
            {
                b[t][0]=x-1;
                b[t][1]=y;
                t++;
                z[x-1][y]=true;
            }

            if(y>0&&!z[x][y-1])
            {
                b[t][0]=x;
                b[t][1]=y-1;
                t++;
                z[x][y-1]=true;
            }

            if(x+1<n&&y+1<m&&!z[x+1][y+1])
            {
                b[t][0]=x+1;
                b[t][1]=y+1;
                t++;
                z[x+1][y+1]=true;
            }

            if(x+1<n&&y>0&&!z[x+1][y-1])
            {
                b[t][0]=x+1;
                b[t][1]=y-1;
                t++;
                z[x+1][y-1]=true;
            }

            if(x>0&&y+1<m&&!z[x-1][y+1])
            {
                b[t][0]=x-1;
                b[t][1]=y+1;
                t++;
                z[x-1][y+1]=true;
            }

            if(x>0&&y>0&&!z[x-1][y-1])
            {
                b[t][0]=x-1;
                b[t][1]=y-1;
                t++;
                z[x-1][y-1]=true;
            }

        }
        l++;
    }

    printf("%d\n",l);

    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