Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
shuiti#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator