中大 9095. Islands
来源:互联网 发布:淘宝的结算方式 编辑:程序博客网 时间:2024/04/28 16:21
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
- Islands
- islands
- zoj Islands
- 岛屿Islands
- 计蒜客 Islands
- Islands UVA
- Using XML Data Islands in Mozilla(Mozilla中使用XML数据岛)
- [pku2288]Islands and Bridges
- UVa 3721 - Islands 【bfs】
- poj 2288 Islands
- POJ 3771 World Islands
- uestc oj 1223 Islands
- hdu 3405 world islands
- sicily 9095 Islands
- hdu 3405 World Islands
- POJ3608-Bridge Across Islands
- POJ2288 Islands and Bridges
- 3.7 read函数-文件数据读
- vs2010下调用matlab2012b调试方法
- C程序编译过程
- Android新闻客户端开发2--主界面业务逻辑实现
- centos6.2/6.4下yum安装phpmyadmin与配置
- 中大 9095. Islands
- postgreSQL的一些sql语句
- UX: useradd: ERROR: Inconsistent password files. See pwconv(1M)
- 使用uWebKit发现的一个问题
- 两个管理的故事(踢猫效应&火鸡的故事)
- 修改oracle服务名
- Oracle 中rank() over()的用法
- 空指针
- Jquery的基本用法