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 ...
随机推荐
- 2018.2.25 关于JavaScript
关于JavaScript 1.数组的归约函数reduce(function(PREV,CUR,I){})会从做导游进行迭代,每次返回的值为下一次的prev参数. 2.在循环遍历数组时若是想在找到结果后 ...
- 拨出网线后,网卡IP丢失
/etc/network/interfaces与NetworkManager 问题:在Centos7上把网线拨出后,发现网卡状态是down,并且网卡上的IP丢失 原因:此网卡被NetworkManag ...
- linux虚拟机配置网络
第一步.网络模式设置为桥接模式 第二步.设置ip和掩码 vim /etc/sysconfig/network-scripts/ifcfg-ens33 ens33为当前机器的网卡名称 在文件尾部添 ...
- Flash as3.0 保存MovieClip运动轨迹到json文件
//放在第一帧调用 import flash.events.Event; import flash.display.MovieClip; stage.addEventListener(Event.EN ...
- label自适应文本大小
UILabel *label = [[UILabelalloc] initWithFrame:CGRectZero]; NSString *string = @"aa2fkoksdajfis ...
- 从 Objective-C 里的 Alloc 和 AllocWithZone 谈起
一.问题起源 一切起源于Apple官方文档里面关于单例(Singleton)的示范代码:Creating a Singleton Instance.主要的争议集中在下面这一段: static MyGi ...
- Mysql数据库插入中文出现乱码相关
查看数据库编码的命令:show variables like "character%"; mysql> show variables like "character ...
- Codeforces Round #513 (rated, Div. 1 + Div. 2)
前记 眼看他起高楼:眼看他宴宾客:眼看他楼坍了. 比赛历程 开考前一分钟还在慌里慌张地订正上午考试题目. “诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省 ...
- Docker 容器的数据管理
docker 容器的数据卷 什么是数据卷(DataVolume) 数据卷是经过特殊计的目录,可以绕过联合文件系统(UFS),为一个或多个容器提供访问. 数据卷设计的目的,在于数据的永久化,它完全独立与 ...
- php读取不到https的域名
因测试环境php遇到无法正常读取到https的域名,但是域名配置了ssl证书,故做如下排查. php测试代码如下 $config['base_url'] = ''; #开启调试模式 #echo &qu ...