POJ 3051 Satellite Photographs
問題文
http://poj.org/problem?id=3051
深さ優先探索やるだけ
char型嫌いでint型好きなので配列はintにした。
JOI予選まであとn日!!!(n <= 4)
#include <cstdio> #include <algorithm> using namespace std; int w,h,t=0,ans=0; int d[1005][90]; int dx[] = {0,-1,0,1}; int dy[] = {1,0,-1,0}; void dfs(int y,int x){ d[y][x] = 0; t++; for(int i = 0;i < 4;i++){ int ny = y + dy[i]; int nx = x + dx[i]; if(ny >= 1 && ny <= h && nx >= 1 && nx <= w && d[ny][nx] == 1){ dfs(ny,nx); } } } int main(){ scanf("%d%d",&w,&h); for(int i = 1;i <= h;i++){ char st[100]; scanf("%s",st); for(int j = 0;j < w;j++){ if(st[j] == '*')d[i][j+1] = 1; } } for(int i = 1;i <= h;i++){ for(int j = 1;j <= w;j++){ if(d[i][j] == 1){ t = 0; dfs(i,j); ans = max(ans,t); } } } printf("%d\n",ans); return 0; }