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

## shuiti

Posted by KatrineYang at 2016-11-12 14:09:25 on Problem 1562
```#include <iostream>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;

int x,y;
bool oil[105][105];

bool inRange(int xx, int yy){
return xx>=0 && xx<x && yy>=0 && yy<y;
}

int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

void dfs(int i, int j, bool used[105][105]){
used[i][j] = 1;
for(int k = 0; k < 8; k++){
int xx = i+dir[k][0], yy = j+dir[k][1];
if(inRange(xx,yy) && oil[xx][yy] && !used[xx][yy]){
dfs(xx,yy,used);
}
}
}

int main() {
while(1){
scanf("%d%d",&x,&y);
if(!x){
break;
}
char hang[233];
for(int i = 0; i < x; i++){
scanf("%s",hang);
for(int j = 0; j < y; j++){
if(hang[j] == '@') oil[i][j] = 1;
else oil[i][j] = 0;
}
}
bool used[105][105] = {0};
int cnt = 0;
for(int i = 0; i < x; i++){
for(int j = 0; j < y; j++){
if(oil[i][j] && !used[i][j]) {
dfs(i,j,used);
cnt++;
}
}
}
printf("%d\n", cnt);
}
return 0;
}
```

Followed by: