中大 9095. Islands
9095. Islands
限制条件
时间限制: 2 秒, 内存限制: 256 兆
题目描述
Whenever it rains, Farmer John's field always ends up flooding. However, since the field isn't perfectly level, it fills up with water in a non-uniform fashion, leaving a number of "islands" separated by expanses of water.
FJ's field is described as a one-dimensional landscape specified by N (1 <= N <= 100,000) consecutive height values H(1)...H(n). Assuming that the landscape is surrounded by tall fences of effectively infinite height, consider what happens during a rainstorm: the lowest regions are covered by water first, giving a number of disjoint "islands", which eventually will all be covered up as the water continues to rise. The instant the water level become equal to the height of a piece of land, that piece of land is considered to be underwater.
An example is shown above: on the left, we have added just over 1 unit of water, which leaves 4 islands (the maximum we will ever see). Later on, after adding a total of 7 units of water, we reach the figure on the right with only two islands exposed. Please compute the maximum number of islands we will ever see at a single point in time during the storm, as the water rises all the way to the point where the entire field is underwater.
输入格式
Line 1: The integer N.
Lines 2..1+N: Line i+1 contains the height H(i). (1 <= H(i) <= 1,000,000,000)
输出格式
Line 1: A single integer giving the maximum number of islands that appear at any one point in time over the course of the rainstorm.
样例输入
835231423
样例输出
4
题目来源
2013年每周一赛第⑨场
这道题的思路是一个岛如果它的左边右边都是水则它的总数就减去1
左边或者右边有一边淹则不变,
两边都不淹则加1;
最边上的两个初始化为1
这道题的难点主要是分析问题
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<cstring>
using namespace std;
struct island
{ int h;
int flage;
int num;
};
island point[100008];//这里有个小技巧point[0],跟point[n+1]初始化为淹
bool operator <(const island &a,const island &b)
{
return a.h<b.h;
}
int main()
{
int i,j,max,n,k,c;
memset(point ,0,sizeof(point));
while(scanf("%d",&n)!=EOF)
{ memset(point ,0,sizeof(point));
for(i=1;i<=n;i++)
{
scanf("%d",&point[i].h);
point[i].num=i;
}
point[0].flage=1;
point[n+1].flage=1;
sort(point,point+n+1);
j=1,max=1,k=1,c=1; for(j=1;j<=n;)
{
int temp;
temp=point[j].h; while(point[j].h==temp)
{
point[point[j].num].flage =1;
if( point[point[j].num-1].flage==0&&point[point[j].num+1].flage==0)
max++;
if(point[point[j].num-1].flage!=0&&point[point[j].num+1].flage!=0)
max--;
j++; }
if(c<=max)
c=max; }
printf("%d\n",c);
}
return 0; }
中大 9095. Islands的更多相关文章
- 中大东校小米路由器mini实现inode上网,ipv6 wifi【中大】【东校】【inode】【ipv6】
还有不到4个月就要毕业了,前几天半夜没事捣鼓小米路由没想到竟然实现了wifi的ipv6. 正好又安利了同学一台小米路由mini,从刷机到inode到ipv6全搞了一遍. 这里将教程写出来,服务学弟妹. ...
- jdbc java数据库连接 11)中大文本类型的处理
1. Jdbc中大文本类型的处理 Oracle中大文本数据类型, Clob 长文本类型 (MySQL中不支持,使用的是text) Blob 二进制类型 MySQL数据库, Text ...
- [LeetCode] Number of Islands II 岛屿的数量之二
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- [LeetCode] Number of Islands 岛屿的数量
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- Leetcode 200. number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- vim中大小写转换
转自:http://www.cnblogs.com/fortran/archive/2010/07/25/1784513.html vim中大小写转化的命令是:gu或者gU,形象一点的解释就是小u意味 ...
- 【leetcode】Number of Islands(middle)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- Javascript中大括号“{}”的多义性
摘要:本文主要介绍JavaScript中大括号有四种语义作用. JS中大括号有四种语义作用 语义1,组织复合语句,这是最常见的 if( condition ) { //... }else { //.. ...
- [LintCode] Number of Islands 岛屿的数量
Given a boolean 2D matrix, find the number of islands. Notice 0 is represented as the sea, 1 is repr ...
随机推荐
- python自学开始
95年工科女一枚 java工程师算不上,只能说从事java开发相关的工作,由于对Python有着极其浓厚的兴趣,一周时间了解大概之后,决定从今天开始见缝插针自学Python,为了防止本人三天打鱼两天晒 ...
- OSX.PackageManager-Homebrew
How to install pip on mac? http://stackoverflow.com/questions/12092306/how-to-install-scipy-with-pip ...
- 从1~N中任选出三个数,最小公倍数最大
已知一个正整数N,问从1~N中任选出三个数,它们的最小公倍数最大可以为多少. 当n为奇数:n.n-1.n-2这是三个最大数,并且它们两两互质.因为连续的奇.偶.奇,互质.连续的两个数互质是因为它们的公 ...
- P1083龙舟比赛
题目如下: 现在正在举行龙舟比赛,我们现在获得了最后冲刺时的俯视图像,现在你要输出各条龙舟的名次. 这张图像由r行c列的字符组成,每行的最左边的字符表示起点,所以字符为'S',最右边的字符为'F'.并 ...
- mysql错误日志
cat /etc/my.cnf
- wmi uuid
[转]https://www.cnblogs.com/-sylar/p/8376621.html 1. 开始-运行-输入:wbemtest 回车2. 单击"连接", 输入:root ...
- 【转载】 了解实时媒体的播放(RTP/RTCP 和 RTSP)
http://blog.csdn.net/span76/article/details/12913307 离线媒体只是用 Http协议去读取服务器端文件而已,而对于实时直播如何实现, 这里就要用到 R ...
- 155. Min Stack - Unsolved
https://leetcode.com/problems/min-stack/#/solutions Design a stack that supports push, pop, top, and ...
- c++中的log函数
引入#include<cmath> 以e为底:log(exp(n)) 以10为底:log10(n) 以m为底:log(n)/log(m)
- java.lang.SuppressWarnings的注解简介
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上.作用:告诉编译器忽略指定的警告, ...