[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

4
3 5
4 8
1 2
5 10

Sample Output

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.

HINT

 

Source

 
题解:
  离散化后差分,l这里+1,r+1那里-1
  即可。
 #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 离散+差分的更多相关文章

  1. BZOJ 2501 [usaco2010 Oct]Soda Machine

    [题意概述] 给出一个[0,1,000,000,000]的整数数轴,刚开始每个位置都为0,有n个区间加操作,最后询问数轴上最大的数是多少. [题解] 我写的是离散化后线段树维护区间最值. 其实貌似不用 ...

  2. [usaco2010 Oct]Soda Machine

    题目描述 有N个人要去膜拜JZ,他们不知道JZ会出现在哪里,因此每个人有一个活动范围,只要JZ出现在这个范围内就能被膜拜, 伟大的JZ当然希望膜拜他的人越多越好,但是JZ不能分身,因此只能选择一个位置 ...

  3. BZOJ2501: [usaco2010 Oct]Soda Machine

    n<=50000个区间,求哪个点被覆盖区间数量最多,输出这个数量. 差分模板..然而数组忘开两倍.. #include<stdio.h> #include<string.h&g ...

  4. Soda Machine【差分+离散化】

    题目链接:https://ac.nowcoder.com/acm/contest/1106/A 题目大意: 1.一条长1e9的线段,每个节点都可以上色.给出n次操作,每次操作将[l, r]区间内的节点 ...

  5. [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游

    [bzoj 1782] [Usaco2010 Feb]slowdown慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N)从 ...

  6. BZOJ 2501 Soda Machine

    BIT+离散化. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  7. BZOJ 4326 NOIP2015 运输计划(树上差分+LCA+二分答案)

    4326: NOIP2015 运输计划 Time Limit: 30 Sec  Memory Limit: 128 MB Submit: 1388  Solved: 860 [Submit][Stat ...

  8. BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会 树形DP

    [Usaco2010 Mar]gather 奶牛大集会 Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来举办这次集会.每个奶牛居住在 N(1 ...

  9. 【树形DP/搜索】BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会

    1827: [Usaco2010 Mar]gather 奶牛大集会 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 793  Solved: 354[Sub ...

随机推荐

  1. CPP-网络/通信:SSL功能和原理

    面对诸多的网上交易的风险,很多网上银行.网上商城在建立系统时都注意到了安全问题.而我们也经常可以看到很多网上银行.电子商务网站在强调本系统的安全性的时候,都说采用了基于数字证书的SSL加密传输.SSL ...

  2. key directories in the linux file system

    Key directories in the file system: */: Root directory (base of file system) /bin: Executable progra ...

  3. 头文件种的ifndef/define/endif 是干什么用的

    头文件种的ifndef/define/endif 是干什么用的? 答:防止头文件被重复包含.

  4. C语言结构体和共用体_07

    概述 定义结构体类型变量的方法 结构体变量的引用 结构体变量的初始化 结构体数组 指向结构体类型数据的指针 用指针处理链表 共用体 枚举类型 用 typedef定义类型  概述 定义一个结构体的一般形 ...

  5. 【构造题 贪心】cf1041E. Tree Reconstruction

    比赛时候还是太慢了……要是能做快点就能上分了 Monocarp has drawn a tree (an undirected connected acyclic graph) and then ha ...

  6. 03IO端口寻址和访问控制方式

    1. I/O端口和寻址 CPU 为了访问 I/O 接口控制器或者控制卡上的数据和状态信息,需要首先指定他们的地址.这种地址就称为I/O端口地址或简称端口.通常一个 I/O 控制器包含访问数据的数据端口 ...

  7. read design into DC memory

  8. 【linux】 服务器文件说明

    文件名 说明 /etc/resolv.conf  域名解析服务器地址文件 /etc/services 服务程序对应端口号文件 /etc/passwd 登录账号文件 /etc/hosts 本地IP域名解 ...

  9. 使用 Python 编写登陆接口

    # 使用 Python 编写登陆接口# Create Date: 2017.10.31 Tuesday# Author: Eric Zhao# -*- coding:utf-8 -*-'''编写登陆接 ...

  10. Applied Nonparametric Statistics-lec10

    Ref:https://onlinecourses.science.psu.edu/stat464/print/book/export/html/14 估计CDF The Empirical CDF ...