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

输入

* 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.

输出

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

样例输入

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

样例输出

16

思路:DFS求最大相连区域,8个方向
 // Satellite Photographs.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; const int MAX = ;
int n, m,ans, vis[MAX][MAX], dir[][] = { , , -, , , , , -};
char map[MAX][MAX]; void DFS(int x, int y, int num)
{
//cout << "x:" << x << "\ty:" << y << "\tnum:" << num << endl;
ans = max(ans, num); for (int i = ; i < ; i++)
{
int nx = x + dir[i][];
int ny = y + dir[i][];
if (nx >= && nx < n && ny >= && ny < m && !vis[nx][ny] && map[nx][ny] == '*')
{
//cout << "nx:" << nx << "\tny:" << ny << endl;
vis[nx][ny] = ;
DFS(nx, ny, num + );
vis[nx][ny] = ;
}
} } int main()
{ memset(vis, , sizeof(vis));
memset(map, '\0', sizeof(map));
ans = ; cin >> m >> n ;
for (int i = ; i < n; i++)
cin >> map[i]; for (int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
if (map[i][j] == '*' && !vis[i][j])
{
vis[i][j] = ;
DFS(i, j, );
vis[i][j] = ;
} }
}
cout << ans << endl; }

 
 

ACM-Satellite Photographs的更多相关文章

  1. Problem I: Satellite Photographs

    Problem I: Satellite Photographs Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 208  Solved: 118 [S ...

  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. 论文学习——《Learning to Compose with Professional Photographs on the Web》 (ACM MM 2017)

    总结 1.这篇论文的思路基于一个简单的假设:专业摄影师拍出来的图片一般具备比较好的构图,而如果从他们的图片中随机抠出一块,那抠出的图片大概率就毁了.也就是说,原图在构图方面的分数应该高于抠出来的图片. ...

  6. ACM会议列表与介绍(2014/05/06)

    Conferences ACM SEACM Southeast Regional Conference ACM Southeast Regional Conference the oldest, co ...

  7. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  8. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  9. acm结束了

    最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!

随机推荐

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:悬停表格

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. 【转载】C#常用控件属性及方法介绍

    C#常用控件属性及方法介绍                                               目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文 ...

  3. 记录一次Git远程仓库版本回退

    操作过程: 首先查看远程仓库版本,如下图所见,最近一次提交为2018-03-19 22:16:25 第一步:使用git log命令查看历史提交记录,选择要回退的版本号,commit后面一串字符,这里我 ...

  4. stm32CubeMx工程使用GCC编译

    软件: STM32CubeMx 5.0 GCC编译器 STM32 ST Link Utility 下载器:ST Link V2 1  安装gcc编译器 能编译ARM Cortex M核的GCC编译器下 ...

  5. 【C++】【STL】【map】基础知识干货

    1.map简介 map是一种关联式容器,主要用于对数据一对一的映射. 2.map的构造 (1)头文件:#include<map> (2)定义:map<第一关键字,第二关键字> ...

  6. BOM--window对象

    BOM 的核心对象是window,它表示浏览器的一个实例.在浏览器中,window 对象有双重角色,它既是通过JavaScript 访问浏览器窗口的一个接口,又是ECMAScript 规定的Globa ...

  7. C++服务器与java进行socket通信案例

    分类: [java]2012-10-08 12:03 14539人阅读 评论(46) 收藏 举报 注:本代码版权所有!!!转载时请声明源地址:http://blog.csdn.net/nuptboyz ...

  8. 用绿色版TOMCAT和绿色版JDK安装一个WEB服务器

    (1) 使用绿色版本JDK,解压到一个目录上D:\jdk1.6.   (2) 使用绿色版本Tomcat,解压到另一个目录上D:\jdk1.6\tomcat5.5 只要在bat文件D:\tomcat5. ...

  9. 工作中一些常用的linux命令

    问题一: 绝对路径用什么符号表示?当前目录.上层目录用什么表示?主目录用什么表示? 切换目录用什么命令? 答案:绝对路径:如/etc/init.d当前目录和上层目录:./  ../主目录:~/切换目录 ...

  10. ROS-2 : ROS系统层级结构

    一.ROS文件系统层级 ROS的文件和文件夹按如下层级来组织: