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

123456

Posted by gaochenjun at 2022-07-19 15:43:17 on Problem 2386
#include<iostream>
using namespace std;
int b[101][101]={0};
char a[101][101];
int num[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
int m,n;
void make(int t,int s)
{
  int i;
  int j,k;
  b[t][s]=1;
  for(i=0;i<8;i++)
  {
    j=t+num[i][0];
    k=s+num[i][1];
    if((a[j][k]=='W')&&(b[j][k]==0)&&(j>=0)
      &&(j<m)&&(k>=0)&&(k<n))
      make(j,k);
  }
}

int main()
{
  int i,j;
  cin>>m>>n;
  for(i=0;i<m;i++)
  {
    for(j=0;j<n;j++)
      cin>>a[i][j];
  }
  int c=0;
  for(i=0;i<m;i++)
  {
    for(j=0;j<n;j++)
    {
      if(a[i][j]=='W'&&b[i][j]==0)
      {
        c++;
        make(i,j);
      }
    }
  }
  cout<<c<<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