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

过了贴代码攒rp

Posted by 1000010314 at 2012-01-23 19:27:14 on Problem 1562
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int data[101][101];
int x[10001],y[10001];
const int around[8][2]={{0,1},{1,0},{1,1},{0,-1},{-1,0},{-1,-1},{1,-1},{-1,1}};
int num,m,n,sum;

void dfs(int kx,int ky)
{
    int p,q;
    data[kx][ky]=num;
    for(int i=0;i<9;i++)
    {
        p=kx+around[i][0];
        q=ky+around[i][1];
        if(p<0||q<0||p>m-1||q>n-1){continue;}
        else if(data[p][q]==-1){dfs(p,q);}
    }
    return;
}


int main()
{
    while(cin>>m>>n)
    {
        if(!n&&!m){break;}
        num=1;
        memset(data,0,sizeof(data));
        memset(x,0,sizeof(x));
        memset(y,0,sizeof(y));
        sum=0;char c[n];
        for(int i=0;i<m;i++)
        {
            scanf("%s",c);
            for(int j=0;j<n;j++)
            {
                if(c[j]=='@')
                {
                    data[i][j]=-1;
                    x[sum]=i;y[sum]=j;
                    sum++;
                }
            }
        }
        for(int i=0;i<sum;i++)
        {
            if(data[x[i]][y[i]]!=-1){continue;}
            dfs(x[i],y[i]);num++;
        }
        num--;
        cout<<num<<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