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. dblink 简单使用

    create extension dblink查看连接:select dblink_get_connections()断开所有连接:select dblink_disconnect()断开指定名称的连 ...

  2. CF987C Three displays 暴力

    题意翻译 题目大意: nnn个位置,每个位置有两个属性s,cs,cs,c,要求选择3个位置i,j,ki,j,ki,j,k,使得si<sj<sks_i<s_j<s_ksi​< ...

  3. Codeforces 350D(计算几何)

    要点 用A.B.C一般式确定每条直线 将合法的圆心中点存到每条直线所属的vector中 枚举所有线段,二分后\(O(1)\)得到其中存在多少答案,累加 #include <cstdio> ...

  4. Django - 回顾(1)- 模型层的Meta选项详解

    一.模型层的Meta选项详解 Django模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性.使用方法及参数解释如下: class Book(models.Model): nid ...

  5. 简述raid0,raid1,raid5,raid10 的工作原理及特点

    RAID 0 支持1块盘到多块盘,容量是所有盘之和 RAID1 只支持2块盘,容量损失一块盘 RAID 5最少三块盘,不管硬盘数量多少,只损失一块容量 RAID 10最少4块盘,必须偶数硬盘,不管硬盘 ...

  6. Java文件与io——字节流

    FileOutputStream用于写入诸如图像数据之类的原始字节的流 字节输出流:OutputStream 此抽象类表示输出字节流的所有类的超类.(写) 字节输入流:InputStream(读) p ...

  7. 【密码学】Https握手协议以及证书认证

    1. 什么是https Https = http + 加密 + 认证 https是对http的安全强化,在http的基础上引入了加密和认证过程.通过加密和认证构建一条安全的传输通道.所以https可以 ...

  8. &&运算符和||运算符的优先级问题 专题

    public class SyntaxTest { @Test public void test() { System.out.println(true || true && fals ...

  9. springboot mybatis 自动生成代码(maven+IntelliJ IDEA)

    1.在pom文件中加入需要的依赖(mybatis-generator-core) 和 插件(mybatis-generator-maven-plugin) <dependency> < ...

  10. Mavlink协议理解

    来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...