题目描述: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. shell脚本中执行sql脚本并传递参数(mysql为例)

    1.mysql脚本文件 t.sql insert into test.t values(@name,@age); exit 2.shell脚本文件 a.sh  (为方便演示,与t.sql文件放在同一目 ...

  2. H5地理定位获取用户当前位置、城市

    第一步:需要在百度地图开发者平台创建一个应用:http://lbsyun.baidu.com/apiconsole/key/create 配置信息 申请配置成功以后返回一个AK 第二步:引入百度地图的 ...

  3. 最短路径问题:Dijkstra算法

    定义 所谓最短路径问题是指:如果从图中某一顶点(源点)到达另一顶点(终点)的路径可能不止一条,如何找到一条路径使得沿此路径上各边的权值总和(称为路径长度)达到最小. 下面我们介绍两种比较常用的求最短路 ...

  4. ios 获取当前系统时间

    1. NSDate + NSDateFormatter NSDate *date = [NSDate date]; NSDateFormatter *format = [[NSDateFormatte ...

  5. VS 项目没有“添加引用”选项

    出问题的环境:vs2017,unity2017unity创建工程后,vs打开项目后,无法添加引用dll,没有“添加引用”项原因: 需要把目标框架改为.

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:分割按钮

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

  7. pygame库的学习

    第一天:我学习了如何设置窗口和加载图片,以及加载音乐.这个库真的很有意思啊,打算py课设就拿这个写了. 代码: import pygamefrom sys import exit pygame.ini ...

  8. TCP为什么三次握手四次挥手

    TCP概述: 它提供面向连接的服务,在传送数据之前必须先建立连接,数据传送完成后要释放连接.因此TCP是一种可靠的的运输服务,也正因为这样,不可避免的增加了许多额外的开销,比如确认,流量控制等.对应的 ...

  9. 01 vue入门

    vue简介 官网上有介绍,这里粘出来 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心 ...

  10. jpa自定义sql语句

    /** * 查询还没生成索引的帖子 * @return */ @Query(value = "SELECT * FROM t_article WHERE index_state=0" ...