[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. PopClip:你会热爱的文本穿梭机

    http://www.ifanr.com/234952 由于我是一名 Evernote 用户(不是印象笔记),最近发现它所提供的浏览器插件无论是 Web Cliper 还是 Clearly,反应速度都 ...

  2. Google 出品的 Java 编码规范,强烈推荐,权威又科学!

    原文:google.github.io/styleguide/javaguide.html 译者:Hawstein 来源:hawstein.com/2014/01/20/google-java-sty ...

  3. Bootstrap历练实例:标签页内的下拉菜单

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  4. mysql 安装简介

    Linux: 安装 [root @ localhost ~]# yum install mysql-server 设定为开机自动启动 [root @ localhost ~]# chkconfig m ...

  5. errno的用法

    Linux中系统调用的错误都存储于 errno中,errno由操作系统维护,存储就近发生的错误,即下一次的错误码会覆盖掉上一次的错误. 编程时需要包含#include <errno.h>, ...

  6. [bzoj]3436 小K的农场

    [题目描述] 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述:农场a比农场b至少多种植了c个单位的 ...

  7. IIS7.0/8.0的错误HTTP Error 500.19 - Internal Server Error ,错误代码为0x80070021

    最近在部署项目的时候,总是出现了这个问题. 大概原因为IIS7.0的安全设定相比前版本有很大的变更.IIS7.0的安全设置文件在%windir%\system32\inetsrv \config\ap ...

  8. phpExcel使用方法二

    require_once './phpexcel/PHPExcel.php'; // 首先创建一个新的对象 PHPExcel object $objPHPExcel = new PHPExcel(); ...

  9. python3 连接 mysql和mariadb的模块

    是pymysql python2中是MySQL-python sudo pip install pymysql 参考博客https://www.jb51.net/article/140387.htm

  10. LeetCode(278)First Bad Version

    题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, t ...