Problem I: Satellite Photographs

Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 208  Solved: 118 [Submit][Status][Web Board]

Description

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.

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.

Output

* Line 1: The size of the largest contiguous field in the satellite photo.

Sample Input

10 5
..*.....**
.**..*****
.*...*....
..****.***
..****.***

Sample Output

16
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[1000][1000];
int sum;
void dfs(int x,int y)
{
if(a[x][y]=='*')//注意是单引号//
{
a[x][y]='.';
sum++;
dfs(x,y+1);
dfs(x,y-1);
dfs(x+1,y);
dfs(x-1,y);
}
else if(a[x][y]=='.')
return ;
}
int main()
{
int w,h;
int i,j,k;
int max;
char c;
sum=0;
scanf("%d%d",&w,&h);
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
scanf(" %c",&a[i][j]);//一定要注意空格,因为换行符也是字符//
}
}
max=0;
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
{
if(a[i][j]=='*')
{
sum=0;//注意初始化sum为0!!!!!!//
dfs(i,j);//从二维数组的第一个*开始搜索//
if(sum>=max)
max=sum;
}
}
}
printf("%d\n",max);
return 0;
}

Problem I: Satellite Photographs的更多相关文章

  1. ACM-Satellite Photographs

    题目描述:Satellite Photographs Farmer John purchased satellite photos of W x H pixels of his farm (1 < ...

  2. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  3. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  4. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  5. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  6. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  7. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  8. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  9. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

随机推荐

  1. Bitbucekt Reference

    Bitbucket Server installation guide https://confluence.atlassian.com/bitbucketserver/bitbucket-serve ...

  2. 原生DOM操作方法小结

    1.0   DOM结构 父节点 兄弟节点 当前节点 属性节点 子节点 兄弟节点 一般任意一个节点我们都会从父节点,子节点,以及兄弟节点的角度去考察.节点一般我们只需关注元素节点,属性节点及文本节点即可 ...

  3. 使用命令行+代理更新Android SDK

    在无桌面的Linux上面安装Jenkins,要配置成Andorid 的持续集成环境Jenkins持续集成Android项目,需要在无桌面的Linux(ubuntu,centos)上安装Android ...

  4. 转 mysql 下载 以及安装

    https://blog.csdn.net/kerafan/article/details/78001849 一.MySQL 各个版本区别 ,(都需要编译的 ) 1.MySQL Community S ...

  5. 使用Telerik StyleMananger 改变Silverlight Button样式

    Telerik 支持更改以下控件样式 System.Windows.Button System.Windows.ScrollViewer System.Windows.CheckBox System. ...

  6. Ubuntu14.04下sogou输入法的输入框只显示英文不显示中文的问题

    解决方法:首先强制更新,把依赖文件全部安装 sudo apt-get install -f 如果仍然不管用,删除sogou的配置文件,在~/.config目录下,一般情况下是SogouPY.Sogou ...

  7. mysql报错this is incompatible with sql_mode=only_full_group_by

    1.报错信息 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP ...

  8. mac-httpd

    mac 的httpd mac 自带了apache2, 但是不推荐使用, 因为它的目录在/Library/WebServer/Documents/下 使用brew install apache-http ...

  9. 关于docker下容器和宿主机器时间不一致问题

    在前几天,在阿里云的ECS上部署一个docker应用时,发现部署的应用在请求第三方应用时,一直出现超时的异常提示,刚开始以为是第三方应用系统的问题(此系统无赖躺枪,反正也不是一次两次了,多躺几次也就习 ...

  10. 冷笑话,idea 按删除键就是undo?

    第一反应是keymap被改了,一看 那么,看起来就是alt出问题了 解决方法 在公司换一个键盘或者狂按alt