题意翻译

为了满足fj所有的N(1<=n<=50000)头奶牛的需求,fj新买了一台汽水机。他想找到一个最完美的位置来安放它。

奶牛的牧场可以被表示为一个一维数轴,第i个奶牛被放牧的区间是[Ai...Bi](包含端点),fj可以把汽水机放在[1..1,000,000,000]。

因为奶牛们都懒得要死,她们想尽可能的少移动。她们希望汽水机被放在自己的放牧区间内。

遗憾的是,fj并不总能满足所有奶牛的要求,所以他想请你帮忙算出他能满足的奶牛数目

题目描述

To meet the ever-growing demands of his N (1 &lt;= N &lt;= 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 &lt;= A_i &lt;= B_i; A_i &lt;= B_i &lt;= 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|---|---|---|---|---|---|---|---|---|---|---|---|-...aaaaaaaaabbbbbbbbbbbbbbbbbccccc           ddddddddddddddddddddd

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当然交给你了

输入格式

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains two space-separated integers: A_i and B_i

输出格式

* Line 1: A single integer representing the largest number of cows whose grazing intervals can all contain the soda machine.

输入输出样例

输入 #1
4
3 5
4 8
1 2
5 10

输出 #1
3

说明/提示

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.

【解题思路】

区间差分

【code】

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 using namespace std;
 5 int n,ans=-1<<30,sum;
 6 struct Node{
 7     int x;
 8     int y;
 9 }a[100005];
10 bool cmp(const Node &a,const Node &b){
11     if(a.x==b.x)return a.y>b.y;
12     return a.x<b.x;
13 }
14 int main(){
15     //freopen("3028.in","r",stdin);
16     //freopen("3028.out","w",stdout);
17     scanf("%d",&n);
18     int s,t;
19     for(register int i=1;i<=n;i++){
20         scanf("%d%d",&s,&t);
21         a[i].x=s;
22         a[i+n].x=t;
23         a[i].y=1;
24         a[i+n].y=-1;
25     }
26     sort(a+1,a+n*2+1,cmp);
27     for(register int i=1;i<=n*2;i++){
28         sum+=a[i].y;
29         ans=max(ans,sum);
30     }
31     printf("%d\n",ans);
32     return 0;
33 }

转载于:https://www.cnblogs.com/66dzb/p/11581942.html

[USACO10OCT]汽水机Soda Machine相关推荐

  1. [usaco2010 Oct]Soda Machine (入门oj Problem 6195 )

    鬼知道我有多蒟蒻,第五次发题解了 题目原地址点此进入 呜呜呜~今天在CSDN上看了好多大佬神犇的OI退役文,百感交集,故写篇题解振奋自己. 文章目录 题目描述 输入 输出 样例输入 样例输出3 题目大 ...

  2. 可口可乐在人工智能和大数据领域的7项应用

    尽管我们有着独特的观察身份来为大家提供投资建议,但我们从不告诉人们他们应该投资哪些股票.相反,我们谈论的是我们做了什么投资,以及我们为什么要做这些投资.用真金白银来验证我们的投资理念.虽然我们主要讨论 ...

  3. 什么是物联网 (IoT)?

    物联网是所有非传统计算机的互联网连接设备的统称.这包括从健身追踪器和智能手表到智能冰箱.耳机.相机.洗衣机.汽车.交通灯.飞机发动机和家庭安全系统的一切. 随着宽带互联网服务接入的增长和处理器变得更加 ...

  4. 企业如何使用商业智能(BI)进行数据赋能?

    导语: 在这个充满波动性.不确定性.复杂性和模糊性的商业环境中,最有力的竞争优势是信息.随着数字化转型成为各类企业的追求,从数据中获取情报的能力将是获胜的关键. 在大多数情况下,这些问题既是技术问题, ...

  5. 【UML】Use Case Diagrams

    文章目录 Use Case Diagrams Introduction Use case Diagram Use Case Diagrams - Actors Use Case Diagrams – ...

  6. GTA圣安地列斯最全攻略

    LOS SANTOS篇 序章任务: CJ在LIBERTY CITY居住了5年,现在终于决定回家,不过刚落机便收到母亲的死讯,没想到 5 年后回家要做的第一件事就是参加母亲的葬礼,刚从机场乘的士往家赶又 ...

  7. SitePoint Podcast#162:以Google为动力

    Episode 162 of The SitePoint Podcast is now available! This week the panel is made up of 3 of our 4 ...

  8. 2021年度训练联盟热身训练赛第二场(全)

    传送门 怎么说呢,这次的训练赛的题目难度不是很大,但就是字多 A Binarize It Professor Boolando can only think in binary, or more sp ...

  9. 2022-2028年中国饮水机市场投资分析及前景预测报告

    [报告类型]产业研究 [报告价格]¥4500起 [出版时间]即时更新(交付时间约3个工作日) [发布机构]智研瞻产业研究院 [报告格式]PDF版 本报告介绍了中国饮水机行业市场行业相关概述.中国饮水机 ...

最新文章

  1. Plugin with id 'com.novoda.bintray-release' not found.的解决方案
  2. 【ECSHOP】格式化商品价格
  3. 在tomcat中部署web项目
  4. 【攻防世界015】notsequence
  5. C# 操作XML入门
  6. C语言头文件深入理解
  7. macd java 源代码_MACD交易系统原理、用法及源代码
  8. aspx页面中使用%= %的注意事项
  9. mysql 字段加comments_Mysql添加注释(comment)(转)
  10. 韩国政府计划从Windows 7迁移到Linux
  11. 免费的json api接口(音乐、物流、地图、视频)
  12. audit2allow命令提示No module named sepolgen.audit
  13. 邓仰东专栏|机器学习的那些事儿(二):机器学习简史
  14. 永久消除自动产生的QQPCMgr
  15. 一些快捷键的用法,linux终端操作下
  16. 37种土豆的制作方法
  17. 区块如何防篡改_一种区块链防篡改技术的优化方法与流程
  18. 联想r7000p双系统ubuntu20.04触摸板失灵
  19. 李开复微博数据分析--微博爬虫、数据挖掘、数据可视化(持续更新)
  20. 读书百客:《渔家傲·天接云涛连晓雾》鉴赏

热门文章

  1. torch Dataloader中的num_workers
  2. DD每周前端七题详解-第五期
  3. 服务器系统登录ilo,华为服务器ILO默认地址
  4. Linux_Learning_兄弟连
  5. 力扣(226.112)补9.8
  6. java毕业设计—— 基于java+JSP+SSH的婴幼儿产品销售系统设计与实现(毕业论文+程序源码)——婴幼儿产品销售系统
  7. 基于python pygame实现的雨点动画
  8. 1.18 Spreadsheet
  9. RecyclerView条目item点击事件---放大
  10. R语言用Rshiny探索lme4广义线性混合模型(GLMM)和线性混合模型(LMM)