[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. js 获取当前年月日时分秒星期

    $("#aa").click(function () { var date = new Date(); this.year = date.getFullYear(); this.m ...

  2. Ecshop首页购物车数量调取问题

    在page_header.lbi中调用SQL: <?php $sql = 'SELECT SUM(goods_number) AS number' . ' FROM ' . $GLOBALS[' ...

  3. 2018.4.19 远程服务器重装系统之后ssh无法登陆问题

    当我们重装云服务器系统的时候输入ssh连接命令(ssh dc2-user@116.85.25.15)出现一下代码 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...

  4. 关于web安全--CSRF和XSS

    CSRF:跨站请求伪造. 攻击原理:一个用户登陆了可信的网站A,身份验证后A会下发一个cookie:此时用户又打开了另一个危险网站B,B引诱用户点击连接(该链接会访问A的接口),由于此时会携带cook ...

  5. Windows10 关闭自动更新

    win+R调出运行窗口: 输入services.msc,查找 跳出服务窗口,点击windows update设置禁用即可 Windows Update Medic Service没办法禁用,需要采用其 ...

  6. MYSQL不能显示中文字,显示错误“ERROR 1366 (HY000): Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89'”

    或者建表时带上编码utf8 CREATE TABLE `students`( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR( ...

  7. salt 模板

    http://www.mamicode.com/info-detail-2297406.html

  8. excel日期格式取年份

    具体思路:先将日期格式更改为常规格式,再取常规格式的前4位数字 例如:A1==1981/12/22 第一步B1=TEXT(A1,"emd") 第二步C1=LEFT(B1,4) 结束

  9. golang(go语言)调试和查看gc信息,以及gc信息解析

    这里记录一下调试golang gc的方法 启用gc打印: # GODEBUG=gctrace=1 go run ./main.go 程序启动后gc将打印如下信息: gc 65 @16.996s 0%: ...

  10. HDU 5111 Alexandra and Two Trees 树链剖分 + 主席树

    题意: 给出两棵树,每棵树的节点都有一个权值. 同一棵树上的节点的权值互不相同,不同树上节点的权值可以相同. 要求回答如下询问: \(u_1 \, v_1 \, u_2 \, v_2\):询问第一棵树 ...