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;
                dfs(i,j);//从二维数组的第一个*开始搜索//
                if(sum>=max)
                    max=sum;
            }
        }
    }
    printf("%d\n",max);
    return 0;
}

原文地址:https://www.cnblogs.com/mjn1/p/8969268.html

时间: 2024-10-23 07:43:41

Problem I: Satellite Photographs的相关文章

POJ 3051 Satellite Photographs

Satellite Photographs Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3051 Description Farmer John purchased satellite photos of W x H pixels of his farm (1 <= W <= 80, 1 <= H <= 1000

深度优先搜索:Satellite Photographs

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 ca

图的深搜应用-Satellite Photographs

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 ca

ACM-Satellite Photographs

题目描述:Satellite Photographs 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

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

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

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

hdu5107 K-short Problem(线段树+离散化+思维)

题目链接: huangjing 题意:就是给出狠点建筑的坐标和高度,然后给出很多询问,求在这个坐标右下角的第k矮的建筑.. 思路:太弱了我,这个题目从上个星期天就开始看,但是一直不会,所以只能看别人思路,因为那个k小于10,所以左右节点只取前十就可以了,但是我觉得万一不记录完全万一发生丢失怎么办,后来一想sb了,如果左右节点都取前10的话,那么根节点得到的20个值,在排序必定取到了前10啊...言归正传,这道题因为数据范围太大了,前对建筑和询问一起排序,按x从小到大,再按y从小到大,在按建筑优先

cs224d problem set2 (三) 用RNNLM模型实现Language Model,来预测下一个单词的出现

今天将的还是cs224d 的problem set2 的第三部分习题, 原来国外大学的系统难度真的如此之大,相比之下还是默默地再天朝继续搬砖吧 (注意前方高能,一大批天书即将来袭) ''' Created on 2017年9月26日 @author: weizhen ''' import getpass import sys import time import numpy as np from copy import deepcopy from utils import calculate_p