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. linux系统中的进程状态分析

    转载地址:https://blog.csdn.net/shenwansangz/article/details/51981459 linux是一个多用户,多任务的系统,可以同时运行多个用户的多个程序, ...

  2. Luogu 4556 雨天的尾巴 - 启发式合并线段树

    Solution 用$col$记录 数量最多的种类, $sum$记录 种类$col$ 的数量. 然后问题就是树上链修改, 求 每个节点 数量最多的种类. 用树上差分 + 线段树合并更新即可. Code ...

  3. 虚函数与bind 实现设计模式的练习

    相同模式使用虚函数与bind function进行实现对比 #include "stdafx.h" #include <iostream> #include <f ...

  4. jedis常用API

    一.Redis Client介绍 1.1.简介 Jedis Client是Redis官网推荐的一个面向java客户端,库文件实现了对各类API进行封装调用. Jedis源码工程地址:https://g ...

  5. Java SE学习【一】

    学java也学了有1个多月了,算算时间,花在上面的时间应该是超过了100个小时了,现在的进度是变量.循环.分支.数组学完了,面向对象部分正在学.记录一下我在学习期间遇到的一些困惑与感想吧! 1.一开始 ...

  6. 《C#从现象到本质》读书笔记(二)第2章 C#类型基础(上)

    <C#从现象到本质>读书笔记第二篇 第2章 C#类型基础(上) 类型指的是集合{类,结构,接口,枚举,委托}中的任意一个成员.任何拥有某类型的值(value)称为某类型的一个实例(inst ...

  7. Java学习笔记:数据校验

    在后台开发过程中,需要对参数进行校验. validation bean 是基于JSR-303标准开发出来的,使用注解的方式实现,是一套规范,可以实现参数的校验. Hibernate Validator ...

  8. MarkDown,写出个性、漂亮的文档

    http://www.markdown.cn # Title1## Title2### Title3content==content2--content3--* name- name+ name * ...

  9. jvm层面锁优化+一般锁的优化策略

    偏向锁: 首先了解对象头MARK指针(对象头标记,32位): 存储GC标记,对象年龄,对象Hash,锁信息(锁记录的指针,偏向锁线程的ID) 大部分情况是没有竞争的,所以可以通过偏向来提高性能 所谓的 ...

  10. [C#]this.Invoke和this.BeginInvoke的区别

    private void button1_Click(object sender, EventArgs e) { "; this.Invoke(new EventHandler(delega ...