POJ 3051 Satellite Photographs
来源:互联网 发布:游戏笔记本电脑知乎 编辑:程序博客网 时间:2024/04/29 10:47
Satellite Photographs
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
Farmer John purchased satellite photos of W x H pixels of his farm (1 <= W <= 80, 1 <= H <= 1000) and wishes to determine the largest 'contiguous' (connected) pasture. Pastures are contiguous when any pair of pixels in a pasture can be connected by traversing adjacent vertical or horizontal pixels that are part of the pasture. (It is easy to create pastures with very strange shapes, even circles that surround other circles.)
Each photo has been digitally enhanced to show pasture area as an asterisk ('*') and non-pasture area as a period ('.'). Here is a 10 x 5 sample satellite photo:
..*.....**
.**..*****
.*...*....
..****.***
..****.***
This photo shows three contiguous pastures of 4, 16, and 6 pixels. Help FJ find the largest contiguous pasture in each of his satellite photos.
Each photo has been digitally enhanced to show pasture area as an asterisk ('*') and non-pasture area as a period ('.'). Here is a 10 x 5 sample satellite photo:
..*.....**
.**..*****
.*...*....
..****.***
..****.***
This photo shows three contiguous pastures of 4, 16, and 6 pixels. Help FJ find the largest contiguous pasture in each of his satellite photos.
Input
* Line 1: Two space-separated integers: W and H
* Lines 2..H+1: Each line contains W "*" or "." characters representing one raster line of a satellite photograph.
* Lines 2..H+1: Each line contains W "*" or "." characters representing one raster line of a satellite photograph.
Output
* Line 1: The size of the largest contiguous field in the satellite photo.
Sample Input
10 5..*.....**.**..*****.*...*......****.***..****.***
Sample Output
16
#include<queue>#include<vector>#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define maxn 1005#define inf 0x3f3f3f3fint w,h;int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};char mp[maxn][maxn];int sum;bool judge(int x,int y){ if(x>=0&&y>=0&&x<h&&y<w&&mp[x][y]=='*')return true; return false;}void dfs(int x,int y){ mp[x][y]='.'; sum++; for(int i=0;i<4;i++){ int nx=x+dir[i][0]; int ny=y+dir[i][1]; if(judge(nx,ny)){ dfs(nx,ny); } }}int main(){ freopen("in.txt","r",stdin); while(scanf("%d%d",&w,&h)!=EOF){ for(int i=0;i<h;i++) scanf("%s",mp[i]); int mas=0; for(int i=0;i<h;i++) for(int j=0;j<w;j++){ if(mp[i][j]=='*'){ sum=0; dfs(i,j); mas=max(mas,sum); } } printf("%d\n",mas); }}
0 0
- poj 3051 Satellite Photographs
- poj-3051 Satellite Photographs
- POJ 3051 Satellite Photographs
- POJ 3051 Satellite Photographs
- POJ 3051 Satellite Photographs 可能会
- POJ 3051 Satellite Photographs 笔记
- POJ 3051 Satellite Photographs 简单DFS
- poj 3051 Satellite Photographs 基础DFS
- poj 3051 Satellite Photographs dp水题
- poj 3051 Satellite Photographs 很基础的dfs
- Satellite Photographs
- POJ 3051 Satellite Photographs 图的连通块,dfs即可。大水题。
- Satellite Photographs
- Satellite Photographs--DFS
- Problem E: Satellite Photographs
- Satellite Photographs(dfs)
- Satellite Photographs(dfs)
- PKU3051 Satellite Photographs 简单DFS
- 浪潮 inspur K-DB 技术白皮书
- android AsyncTask介绍
- Codeforces Round #292 (Div. 2)
- [sig13]Lighting technology of "The Last Of Us"
- Linux进程实践(3) --进程终止与exec函数族
- POJ 3051 Satellite Photographs
- 产品经理如何评估产品机会
- Leetcode:Unique Binary Search Trees: 菜鸟解法
- SGU200 Cracking RSA
- HDU 1016 Oil Deposits
- C#与.NET 的关系
- 对象概述
- Leetcode: Generate Parentheses
- C#:arcengine 由FeatureClass创建Tin