Problem I: Satellite Photographs
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的更多相关文章
- ACM-Satellite Photographs
题目描述:Satellite Photographs Farmer John purchased satellite photos of W x H pixels of his farm (1 < ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
随机推荐
- Scrapy框架初探
Scrapy 貌似是 Python 最出名的爬虫框架 0. 文档 中文文档:https://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.ht ...
- 设计模式——懒汉式单例类PK饿汉式单例类
前言 我们都知道生活中好多小软件,有的支持多IP在线,有的仅仅局限于单个IP在线.为什么这样设计,在软件开发阶段就是,有需求就是发展.这就是软件开发的一个设计模式--懒汉式单例类和饿汉式单例类. 内容 ...
- 洛谷P1312 Mayan游戏
P1312 Mayan游戏 题目描述 Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个 7 行5 列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他 ...
- 对zabbix监控磁盘性能的补充
原因 在上一篇文章中,我写了完整的磁盘监控步骤,希望对大家有所帮助.但是这里还需要作出一点补充. 根据上一篇文章的内容,我是使用iostat命令不停的收集磁盘的信息,然后写入到/tmp/iostat_ ...
- css奇技淫巧—box-shadow与outline绘制多重边框效果
css语法: box-shadow: h-shadow v-shadow blur spread color inset; 注释:box-shadow 向框添加一个或多个阴影.该属性是由逗号分隔的阴影 ...
- oracle数据库的导入导出命令
说明:将以下命令复制到cmd命令行中运行即可,file代表文件名数据导入imp zzbweb/zzbweb@orcl file=e:\zzbweb.dmp fromuser=zzbweb touser ...
- jetty-env.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE Configure PUBLIC &quo ...
- 查询时根据权限更改sql
import java.lang.reflect.Method; import org.apache.log4j.Logger; import org.springframework.aop.Meth ...
- chapter06
/** * Created by EX-CHENZECHAO001 on 2018-03-30. */class Chapter06 { } // 6 对象// 用对象作为单例或存放工具的方法// 类 ...
- spring boot test MockBean
使用spring boot , MockBean @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) p ...