ACM-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的更多相关文章
- Problem I: Satellite Photographs
Problem I: Satellite Photographs Time Limit: 1 Sec Memory Limit: 128 MB Submit: 208 Solved: 118 [S ...
- 杭电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. ...
- 论文学习——《Learning to Compose with Professional Photographs on the Web》 (ACM MM 2017)
总结 1.这篇论文的思路基于一个简单的假设:专业摄影师拍出来的图片一般具备比较好的构图,而如果从他们的图片中随机抠出一块,那抠出的图片大概率就毁了.也就是说,原图在构图方面的分数应该高于抠出来的图片. ...
- ACM会议列表与介绍(2014/05/06)
Conferences ACM SEACM Southeast Regional Conference ACM Southeast Regional Conference the oldest, co ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- acm结束了
最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!
随机推荐
- 初学微信小程序——配置问题(2)
六.生命周期函数: 在微信公众平台指南中搜索生命周期,找到页面生命周期 比如,我打开cate.js并编写,代码如下: ** * 生命周期函数--监听页面加载 */ onLoad: function ...
- 怎样实现android 返回到上一个Activity并重新执行一次onCreate方法
1.onCreate 方法只在activity一开始创建的时候执行.2.也就是在该activity销毁后才能再次执行,假如当前activity上再打开一个activity,并且原来的activity已 ...
- NoNodeAvailableException异常的解决
Elasticsearch 相关学习,昨天还好好的,今天就出错了!!! 完整异常为 : NoNodeAvailableException[None of the configured nodes ar ...
- zabbix4.4安装 centos7+mysql+Nginx
1.安装数据源 # rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch. ...
- ssm框架前后端数据交互完整示例
1.sprinMvc控制层 package com.dengfeng.house.controller; import java.text.ParseException; import java.ut ...
- 使用Vue 和 内网穿透:返回 invalid host header
原因:新版的webpack-dev-server出于安全考虑,默认检查hostname,如果它不是配置内的,将会中断访问. -------------------------------------- ...
- jenkins -- 邮件的配置
参考博文:https://blog.csdn.net/lykio_881210/article/details/81135769 https://www.jianshu.com/p/29a29ce6e ...
- 宏碁发布两款全A平台笔记本:良心价
导读 8月3日消息,在全球数码互动娱乐盛会ChinaJoy上,宏碁推出全新两款全A平台笔记本——暗影骑士4 锐龙版酷冷游戏本和蜂鸟Swift3锐龙版金属轻薄本. 此次发布的宏碁暗影骑士4 锐龙版笔记本 ...
- Springboot注解使用总结
使用Spring boot已经有段时间了,但是对很多注解的使用经常会遇到模糊甚至不解的地方,这次有时间便总结一下. 注解(Annotation)概念 注解是Java5开始对元数据的支持,注解与注释是有 ...
- 【LOJ6498】「雅礼集训 2018 Day2」农民
题面 solution 直接暴力模拟,原数据可获得满分的成绩. 对于每个点,其父亲对其都有一个限制.故我们只需要判断当前点到根的路径上的限制是否都能满足即可. 考虑用树剖+线段树维护这个限制.考虑到翻 ...