High bridge, low bridge

Q:There are one high bridge and one low bridge across the river. The river has flooded twice, why the
high bridge is flooded twice but the low bridge is flooded only once?
A: Because the lower bridge is so low that it’s still under water after the first flood is over.
If you’re confused, here’s how it happens:
• Suppose high bridge and low bridge’s heights are 2 and 5, respectively, and river’s initial water
level is 1.
• First flood: the water level is raised to 6 (Both bridges are flooded), and then back to 2 (high
bridge is not flooded anymore, but low bridge is still flooded).
• Second flood: the water level is raised to 8 (The high bridge is flooded again), and then back to
3.
Just a word game, right? The key is that if a bridge is still under water (i.e. the water level is no
less than the bridge height) after a flood, then next time it will not be considered flooded again.
Suppose the i-th flood raises the water level to ai and then back to bi
. Given n bridges’ heights,
how many bridges are flooded at least k times? The initial water level is 1.
Input
The input contains at most 25 test cases. Each test case begins with 3 integers n, m, k in the first line
(1 ≤ n, m, k ≤ 105
). The next line contains n integers hi
, the heights of each bridge (2 ≤ hi ≤ 108
).
Each of the next m lines contains two integers ai and bi (1 ≤ bi < ai ≤ 108
, ai > bi−1). The file size of
the whole input does not exceed 5MB.
Output
For each test case, print the number of bridges that is flooded at least k times.
Explanation:
For the second sample, 5 bridges are flooded 1, 2, 3, 2, 0 times, respectively.
Sample Input
2 2 2
2 5
6 2
8 3
5 3 2
2 3 4 5 6
5 3
4 2
5 2
Sample Output
Case 1: 1
Case 2: 3

题解:涨潮,问会被淹没超过k次的桥的个数;

由于数据过大,要离散化下,这次涨潮要在上次最低潮的基础上也就是前一个x +1 到y;这之间加上1;最后只需要统计个数就好了;

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + ;
int num[MAXN * ];
int brige[MAXN];
int l[MAXN], r[MAXN];
int cnt[MAXN * ];
int main(){
int n, m, p;
int kase = ;
while(~scanf("%d%d%d", &n, &m, &p)){
int tp = ;
num[tp++] = ;
for(int i = ; i < n; i++){
scanf("%d", brige + i);
num[tp++] = brige[i];
}
for(int i = ; i < m; i++){
scanf("%d%d", r + i, l + i);
num[tp++] = r[i];
num[tp++] = l[i];
}
sort(num, num + tp);
int k = unique(num, num + tp) - num;
memset(cnt, , sizeof(cnt));
int x, y, last = lower_bound(num, num + k, ) - num;
for(int i = ; i < m; i++){
x = lower_bound(num, num + k, l[i]) - num;
y = lower_bound(num, num + k, r[i]) - num;
int lx = last;
if(lx > y)swap(lx, y);
cnt[lx + ]++;
cnt[y + ]--;
last = x;
}
for(int i = ; i <= k; i++)
cnt[i] += cnt[i - ];
int ans = ;
for(int i = ; i < n; i++){
x = lower_bound(num, num + k, brige[i]) - num;
// printf("%d ", cnt[x]);
if(cnt[x] >= p)
ans++;
}
printf("Case %d: %d\n", ++kase, ans);
}
return ;
}

High bridge, low bridge(离散化, 前缀和)的更多相关文章

  1. P2344 奶牛抗议 离散化+前缀和+动态规划+树状数组

    [题目背景] Generic Cow Protests, 2011 Feb [题目描述] 约翰家的N 头奶牛正在排队游行抗议.一些奶牛情绪激动,约翰测算下来,排在第i 位的奶牛的理智度为Ai,数字可正 ...

  2. 北桥芯片(north bridge/host bridge)

    看下上面的图,会比较清晰的认识到北桥芯片所在位置 北桥芯片(North Bridge) 是mother board chipset(主板芯片组) 中起主导作用的最重要的组成部分,也称为主桥(Host ...

  3. Dull Chocolates Gym - 101991D 离散化 前缀和

    题目链接:https://vjudge.net/problem/Gym-101991D 具体思路:首先看数据范围,暴力肯定不可以,可以下离散化,然后先求出离散化后每一个点到(1,1)的符合题目的要求的 ...

  4. 2019 ICPC Asia Nanchang Regional E Eating Plan 离散化+前缀和

    题意: 给你n个盘子,这n个盘子里面分别装着1!到n!重量的食物,对于每一个询问k,找出一个最短的区间,使得区间和 mod 998857459 大于或等于k 盘子数量 n<=1e5 询问次数 m ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem H

    Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...

  6. nenu contest3

    http://vjudge.net/contest/view.action?cid=55702#overview 12656 - Almost Palindrome http://uva.online ...

  7. 理解 neutron(15):Neutron linux-bridge-agent 创建 linux bridge 的简要过程

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

  8. KVM 虚拟机联网方式:NAT 和 Bridge

    KVM 客户机网络连接有两种方式: 用户网络(User Networking):让虚拟机访问主机.互联网或本地网络上的资源的简单方法,但是不能从网络或其他的客户机访问客户机,性能上也需要大的调整.NA ...

  9. Neutron 理解(14):Neutron ML2 + Linux bridge + VxLAN 组网

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

随机推荐

  1. 【编程范式】汇编解释swap方法

    先要熟悉一些汇编的基本知识: 1.SP是什么? SP是堆栈寄存器,在调用子程序时,都会用到,保存原来程序的环境使用,如各个寄存器的内容,最重要的是,调用返回时程序的运行指令地址,这是由调用时将返回地址 ...

  2. 在Unity中使用Shader

    1.Material 和 Shader 的关系.一个材质包括一个Shader程序.在Shader中设置的属性能够通过Material可视化设置 2.内建Shader,在5.0之后的版本号中大部分旧的S ...

  3. sdut2623--The number of steps(概率dp第一弹,求期望)

    The number of steps Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 Mary stands in a st ...

  4. string之substring的用法

    package com.j1; public class StringTest1 { public static void main(String[] args) { String s =" ...

  5. nagios和zabbix自定义监控脚本

    一. 自定义nagios监控脚本1. 在客户端上创建脚本/usr/local/nagios/libexec/check_disk.shvim  /usr/local/nagios/libexec/ch ...

  6. EF中加载实体的方式

    EF中的查询执行时机:1. foreach进行枚举2. ToArray.ToList.ToDictionary3. Linq的一些操作,如First.Any4. DbSet上的Load操作.DbEnt ...

  7. 软件工程师所需掌握的“终极技术”是什么?

    软件工程师所需掌握的"终极技术"是什么? http://yunli.blog.51cto.com/831344/1019990 最近,我在微博上看到@程序员邹欣老师发的一条微博 - ...

  8. Oracle11g R2学习系列 之二基本概念和环境介绍

    昨天安装好了之后,发现用Chrome打开OEM发现是英文的,搞得我好奇怪:安装时明明自动显示的是中文的,为何会是英文的呢.后来想想会不会是Oracle用的是浏览器的语言呢,果断打开Chrome的设置, ...

  9. javascript的全局变量

    javascipt是一门面向对象的编程语言.由于存在一些全局属性及全局函数,因此可以认为存在一个全局变量,这些全局属性及全局函数均是其属性或函数. 在js核心中,并没有定义一个具体的全局变量,因此,j ...

  10. 关于jquery-easyUI中主键属性data-options的了解

    data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我们可以对easyui组件的实例化可以完全写入到html中,例如: <div class=& ...