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

用 bool16ms,用char 0ms

Posted by czjxy881 at 2012-07-27 19:49:53 on Problem 1562
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
char map[102][102];
void v(int x,int y,int n)
{
    if(n>100||!map[x][y])return;
    map[x][y]=0;n++;
    v(x-1,y-1,n);v(x,y-1,n);v(x+1,y-1,n);
    v(x-1, y ,n);           v(x+1, y ,n);
    v(x-1,y+1,n);v(x,y+1,n);v(x+1,y+1,n);
    return;
}
bool solve()
{
    int m,n,i,j,ans=0;
    scanf("%d%d",&m,&n);
    if(!(m+n))return 0;
    char t;
    for(i=1;i<=m;i++)
    {
      while(getchar()!='\n');
      for(j=1;j<=n;j++)
      {
          t=getchar();
          if(t=='@')map[i][j]=1;
          else map[i][j]=0;
      }
      map[i][j]=0;
    }
    for(j=1;j<=n;j++) map[i][j]=0;
    for(i=1;i<=m;i++)
      for(j=1;j<=n;j++)
         if(map[i][j]){ans++;v(i,j,1);}
    printf("%d\n",ans);
    return 1;
}
int main()
{
    while(solve());
    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