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的更多相关文章

  1. 中大东校小米路由器mini实现inode上网,ipv6 wifi【中大】【东校】【inode】【ipv6】

    还有不到4个月就要毕业了,前几天半夜没事捣鼓小米路由没想到竟然实现了wifi的ipv6. 正好又安利了同学一台小米路由mini,从刷机到inode到ipv6全搞了一遍. 这里将教程写出来,服务学弟妹. ...

  2. jdbc java数据库连接 11)中大文本类型的处理

    1. Jdbc中大文本类型的处理 Oracle中大文本数据类型, Clob    长文本类型   (MySQL中不支持,使用的是text) Blob    二进制类型 MySQL数据库, Text   ...

  3. [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 ...

  4. [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 ...

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

  6. vim中大小写转换

    转自:http://www.cnblogs.com/fortran/archive/2010/07/25/1784513.html vim中大小写转化的命令是:gu或者gU,形象一点的解释就是小u意味 ...

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

  8. Javascript中大括号“{}”的多义性

    摘要:本文主要介绍JavaScript中大括号有四种语义作用. JS中大括号有四种语义作用 语义1,组织复合语句,这是最常见的 if( condition ) { //... }else { //.. ...

  9. [LintCode] Number of Islands 岛屿的数量

    Given a boolean 2D matrix, find the number of islands. Notice 0 is represented as the sea, 1 is repr ...

随机推荐

  1. 12. pt-index-usage

    pt-index-usage h=192.168.100.101,P=3306,u=admin,p=admin /data/mysql3306/data/slow.log 根据slow log来判断i ...

  2. centos7中输入ifconfig出现ens33,没有eth0(转)

    vmware安装的centos7中没有出现eth0网卡,也没有ip,不能上网,输入ifconfig后如下图 解决办法 1.编辑网卡的配置文件 vi /etc/sysconfig/network-scr ...

  3. TCHAR函数查询

    https://blog.csdn.net/is2120/article/details/27542927

  4. default(T) 和 typeof 和 GetType()

    一.default(T) 在泛型编成中如果不限制T类型参数是值类型或引用类型的话 你程序内部可能会出现错误,因为值类型不允许NULL.所以default用来获取一个类型的默认值,对于值类型得到new ...

  5. JS在页面根据数量改变总价及按钮进行格式验证

    分两部分,第一部分是在页面上,根据数量的input标签内容,动态更新总价标签的内容,代码如下: <script type="text/javascript"> $(do ...

  6. 【Linux】DNS服务-BIND基础配置(二)

    BIND简介 现在使用最为广泛的DNS服务器软件是BIND(Berkeley Internet Name Domain),最早有伯克利大学的一名学生编写,现在最新的版本是9,有ISC(Internet ...

  7. 关于SSH中tomcat下中文名称图片不显示的问题

    最近做一个SSH框架的项目,用tomcat发布,需要上传图片到指定路径,然后再将图片显示在页面上.有一个问题:如果是英文名称的图片,就正常显示,可如果是中文的,它就是显示不出来,于是乎,在网上各种百度 ...

  8. MyBatis 实现新增

    MyBatis实现新增 1.概念学习:(角度不同) 1.1 功能:从应用程序角度出发,软件具有哪些功能 1.2 业务:完成功能时的逻辑,对应Service中一个方法 1.3 事务:从数据库角度出发,完 ...

  9. 【转】linux 磁盘挂载

    挂载好新硬盘后输入fdisk -l命令看当前磁盘信息 可以看到除了当前的第一块硬盘外还有一块sdb的第二块硬盘,然后用fdisk /dev/sdb 进行分区 进入fdisk命令,输入h可以看到该命令的 ...

  10. 2019.01.22 51nod 1203 JZPLCM(线段树+链表)

    传送门 一道很有意思的题. 题意简述:给一个数列,多次询问区间的lcmlcmlcm,答案对1e9+71e9+71e9+7取模. 思路:首先考虑到一个区间的lcmlcmlcm就是其中所有出现过的素数的最 ...