BZOJ 2501: [usaco2010 Oct]Soda Machine 离散+差分
[usaco2010 Oct]Soda Machine
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 266 Solved: 182
[Submit][Status][Discuss]
Description
To meet the ever-growing demands of his N (1 <= N <= 50,000) cows,
Farmer John has bought them a new soda machine. He wants to figure
out the perfect place to install the machine.
The field in which the cows graze can be represented as a one-dimensional
number line. Cow i grazes in the range A_i..B_i (1 <= A_i <= B_i;
A_i <= B_i <= 1,000,000,000) (a range that includes its endpoints),
and FJ can place the soda machine at any integer point in the range
1..1,000,000,000. Since cows are extremely lazy and try to move
as little as possible, each cow would like to have the soda machine
installed within her grazing range.
Sadly, it is not always possible to satisfy every cow's desires.
Thus FJ would like to know the largest number of cows that can be
satisfied.
To demonstrate the issue, consider four cows with grazing ranges
3..5, 4..8, 1..2, and 5..10; below is a schematic of their grazing
ranges:
1 2 3 4 5 6 7 8 9 10 11 12 13
|---|---|---|---|---|---|---|---|---|---|---|---|-...
aaaaaaaaa
bbbbbbbbbbbbbbbbb
ccccc ddddddddddddddddddddd
Sample Output
As can be seen, the first, second and fourth cows share the point 5,
but the third cow's grazing range is disjoint. Thus, a maximum of
3 cows can have the soda machine within their grazing range.
有N个人要去膜拜JZ,他们不知道JZ会出现在哪里,因此每个人有一个活动范围,只要JZ出现在这个范围内就能被膜拜,
伟大的JZ当然希望膜拜他的人越多越好,但是JZ不能分身,因此只能选择一个位置出现,他最多可以被多少人膜拜呢,
这个简单的问题JZ当然交给你了
3 OUTPUT DETAILS: If the soda machine is placed at location 5, cows 1, 2, and 4 can be
satisfied. It is impossible to satisfy all four cows.
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains two space-separated integers: A_i
and B_i
Output
* Line 1: A single integer representing the largest number of cows
whose grazing intervals can all contain the soda machine.
Sample Input
3 5
4 8
1 2
5 10
Sample Output
OUTPUT DETAILS:
If the soda machine is placed at location 5, cows 1, 2, and 4 can be
satisfied. It is impossible to satisfy all four cows.
HINT
Source
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib> #define N 50007
#define ll long long
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n;
int l[N],r[N],sum[N*];
int tot,a[N*]; int main()
{
n=read();
for (int i=;i<=n;i++)
{
l[i]=read(),r[i]=read()+;
a[++tot]=l[i],a[++tot]=r[i];
}
sort(a+,a+tot+);
for (int i=;i<=n;i++)
{
l[i]=lower_bound(a+,a+tot+,l[i])-a;
r[i]=lower_bound(a+,a+tot+,r[i])-a;
sum[l[i]]++;
sum[r[i]]--;
}
int ans=;
for (int i=;i<=tot;i++)
{
sum[i]=sum[i]+sum[i-];
ans=max(ans,sum[i]);
}
printf("%d\n",ans);
}
BZOJ 2501: [usaco2010 Oct]Soda Machine 离散+差分的更多相关文章
- BZOJ 2501 [usaco2010 Oct]Soda Machine
[题意概述] 给出一个[0,1,000,000,000]的整数数轴,刚开始每个位置都为0,有n个区间加操作,最后询问数轴上最大的数是多少. [题解] 我写的是离散化后线段树维护区间最值. 其实貌似不用 ...
- [usaco2010 Oct]Soda Machine
题目描述 有N个人要去膜拜JZ,他们不知道JZ会出现在哪里,因此每个人有一个活动范围,只要JZ出现在这个范围内就能被膜拜, 伟大的JZ当然希望膜拜他的人越多越好,但是JZ不能分身,因此只能选择一个位置 ...
- BZOJ2501: [usaco2010 Oct]Soda Machine
n<=50000个区间,求哪个点被覆盖区间数量最多,输出这个数量. 差分模板..然而数组忘开两倍.. #include<stdio.h> #include<string.h&g ...
- Soda Machine【差分+离散化】
题目链接:https://ac.nowcoder.com/acm/contest/1106/A 题目大意: 1.一条长1e9的线段,每个节点都可以上色.给出n次操作,每次操作将[l, r]区间内的节点 ...
- [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游
[bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...
- BZOJ 2501 Soda Machine
BIT+离散化. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...
- BZOJ 4326 NOIP2015 运输计划(树上差分+LCA+二分答案)
4326: NOIP2015 运输计划 Time Limit: 30 Sec Memory Limit: 128 MB Submit: 1388 Solved: 860 [Submit][Stat ...
- BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会 树形DP
[Usaco2010 Mar]gather 奶牛大集会 Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会.每个奶牛居住在 N(1 ...
- 【树形DP/搜索】BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会
1827: [Usaco2010 Mar]gather 奶牛大集会 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 793 Solved: 354[Sub ...
随机推荐
- python基础一 day15 面试题
# def demo():# for i in range(4):# yield i## g=demo()## g1=(i for i in g)# g2=(i for i in g1)## prin ...
- Verilog设计分频器(面试必看)
分频器是指使输出信号频率为输入信号频率整数分之一的电子电路.在许多电子设备中如电子钟.频率合成器等,需要各种不同频率的信号协同工作,常用的方法是以稳定度高的晶体振荡器为主振源,通过变换得到所需要的各种 ...
- Hbase 完全分布式 高可用 集群搭建
1.准备 Hadoop 版本:2.7.7 ZooKeeper 版本:3.4.14 Hbase 版本:2.0.5 四台主机: s0, s1, s2, s3 搭建目标如下: HMaster:s0,s1(备 ...
- php的字符转换 & php登入注册界面设计以及源码 & 分离公共部分
我们在编写的时候总是会出现乱码 https://www.cnblogs.com/mafeng/p/5827215.html php登入注册界面设计以及源码 https://blog.csdn.net/ ...
- CVE-2014-1767
[0x00].简介 CVE-2014-1767漏洞是由于Windows的afd.sys驱动在对系统内存的管理操作中,存在着悬垂指针的问题.在特定情况下攻击者可以通过该悬垂指针造成内存的double ...
- HTML5<figure>元素
HTML5<figure>元素是用来定义页面文档中独立的流内容(图像,图表,照片,代码块),figure内容与主内容有关,如果被删除,则不影响主文档流的产生. HTML5<figca ...
- debian常用指令
查看软件xxx安装内容 dpkg -L xxx 查找软件 apt-cache search 正则表达式 查找文件属于哪个包 dpkg -S filename apt-file search filen ...
- 【数论分块】bzoj2956: 模积和
数论分块并不精通……第一次调了一个多小时才搞到60pts:因为不会处理i==j的情况,只能枚举了…… Description $\sum_{i=1}^{n}\sum_{j=1 \land i \not ...
- mongo 副本集+分片 配置
服务器规划如下: 副本集名称|服务器IP 192.168.56.111 192.168.56.112 192.168.56.113 shard1 3201 3201 3201 shard2 3202 ...
- Cacti安装脚本Server端+客户端
#!/bin/bash #auto make install LAMP+Cacti #by authors zhang #RRDtool define path variable R_FILES=rr ...