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. MySql数据库 sql查询增加序号的伪列

    在查询数据库的时候,我们有时候需要对查询出来的数据加上序列,1,2,3,……n 例如:我们根据表的某个字段排序后,要对这些数据加上序列,这个时候序号常常不是我们建表时设置好的自增的主键id,怎么办呢? ...

  2. Java与go哪个更适合后端开发呢?哪个更适合新手呢?

    Java语言目前在后端开发领域有广泛的应用,尤其是大型互联网平台往往选择Java作为主要的后端编程语言.同时,Java自身的生态比较健全,也有大量的成功案例,所以采用Java做后端编程语言是一个风险比 ...

  3. 修改别人写的Hibernate数据库操作代码

    最近正在维护别人写的一个关于Hibernate操作数据库的项目,在运行测试的时候(向表中插入记录),报了一个错误:cannot insert a null into column(XXX字段名,下文统 ...

  4. BZOJ1999或洛谷1099&BZOJ2282或洛谷2491 树网的核&[SDOI2011]消防

    一道树的直径 树网的核 BZOJ原题链接 树网的核 洛谷原题链接 消防 BZOJ原题链接 消防 洛谷原题链接 一份代码四倍经验,爽 显然要先随便找一条直径,然后直接枚举核的两个端点,对每一次枚举的核遍 ...

  5. Servlet会话管理一(URL重写和表单隐藏域)

    会话可以简单的理解为客户端用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器的整个过程称为一个会话.即一个客户端用户和服务器端进行通讯的过程,也是客户端和服务器端之间的数据传 ...

  6. Python之路番外(第三篇):Pycharm的使用秘籍

    版本:Pycharm2017.3.4Professional Edition 一.Pycharm的基本使用1.在Pycharm下为你的python项目配置python解释器 file --settin ...

  7. Python3实战系列之二(获取印度售后数据项目)

    问题:续接上一篇.说干咱就干呀,勤勤恳恳写程序呀! 目标:安装python和pycharm.要编写并运行python程序就需要电脑有开发工具和运行环境,所以此篇就是安装编辑和运行python程序的软件 ...

  8. Spring整合jedis 集群模式

    引入jedis依赖 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis< ...

  9. UVA 10405 Longest Common Subsequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&p ...

  10. python输出格式对齐问题

    采用.format打印输出时,可以定义输出字符串的输出宽度,在 ':' 后传入一个整数, 可以保证该域至少有这么多的宽度. 用于美化表格时很有用. >>> table = {'Goo ...