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 ...
随机推荐
- Java:基本语法
Java语言是由类和对象组成的,其对象和类又是由变量和方法组成,而方法,又包含了语句和表达式. 1. 变量 Java语言提供了两种变量:成员变量和局部变量 成员变量:是在方法体外的类中声明和定义的,可 ...
- Macbook sublime 安装markdown插件
Sublime Text为3 版本 安装sublime text 插件,需要“***”,不会弄的,就可以移步了. 首先按 command + shift + p 调出安装插件的界面,输入“instal ...
- 课堂笔记 layout 布局、手风琴accordion、选项卡tabs
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Gdiplus的使用 gdi+
使用步骤: 1.包括相应的头文件及引入相应的lib 1 #include <GdiPlus.h> 2 #pragma comment(lib, "gdiplus.lib" ...
- EIGRP-3-EIGRP的多参数度量
带宽度量参数本身无法区分10Gbit/s及更高速率的接口.对1Gbit/s接口,默认延迟度量参数已设置为最低值1(10微妙).而且EIGRP承载的是经过换算的参数,每台路由器需要将其换算回再计算新开销 ...
- Django---登录(含随机生成图片验证码)、注册示例讲解
登录(验证码).注册功能具体代码 # urls.py from django.contrib import admin from django.urls import path from app01 ...
- beeline连接hive
beeline -u jdbc:hive2://192.168.1.77:10000 zeppelin default jdbc: jdbc:hive2://nn01.ooccpp.com:2181/ ...
- chapter09
import java.io.File import java.nio.file._ import scala.collection.mutable.ArrayBuffer/** * Created ...
- webissue 搭建 issue 分析工具
http://www.cnblogs.com/feiyun8616/p/6208423.html
- 《从0到1学习Flink》—— Data Sink 介绍
前言 再上一篇文章中 <从0到1学习Flink>-- Data Source 介绍 讲解了 Flink Data Source ,那么这里就来讲讲 Flink Data Sink 吧. 首 ...