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 |
怒水一发#include <iostream> #include <stdio.h> using namespace std; int N, M; bool isLake[120][120] = {0}; bool used[120][120] = {0}; bool inRange(int x, int y){ return x >= 0 && x < N && y >= 0 && y < M; } int dir[8][2] = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; void dfs(int x, int y){ used[x][y] = 1; for(int i = 0; i < 8; i++){ int x_ = x+dir[i][0], y_ = y+dir[i][1]; if(inRange(x_,y_) && isLake[x_][y_] && !used[x_][y_]){ dfs(x_,y_); } } } int main() { scanf("%d%d", &N, &M); for(int i = 0; i < N; i++){ char data[120]; scanf("%s", data); for(int j = 0; j < M; j++){ if(data[j] == 'W') isLake[i][j] = 1; } } int cnt = 0; for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ if(!isLake[i][j] || used[i][j]) continue; cnt++; dfs(i, j); } } 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