POJ_3051_Satellite Photographs

#include <iostream> using namespace std; int w, h; int step[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; int visit[1001][81]; char map[1001][81]; int ans; bool Check(int x, int y) { if (x >= h || x < 0 || y >= w || y < 0) return false; return true; } void DFS(int CurX, int CurY) { ans++; visit[CurX][CurY] = 1; for (int i = 0; i < 4; i++) { int x = CurX+step[i][0]; int y = CurY+step[i][1]; if (Check(x, y) == false || visit[x][y] == 1) continue; if (map[x][y] == '*') DFS(x, y); } } int main() { freopen("test.txt", "r", stdin); memset(visit, 0, sizeof(visit)); cin>>w>>h; for (int i = 0; i < h; i++) cin>>map[i]; int res = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (visit[i][j] == 0 && map[i][j] == '*') { ans = 0; DFS(i, j); res = max(res, ans); } } } cout<<res<<endl; return 0; } 

 

 

你可能感兴趣的:(POJ_3051_Satellite Photographs)