博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P2970 [USACO09DEC]自私的放牧Selfish Grazing
阅读量:5291 次
发布时间:2019-06-14

本文共 2580 字,大约阅读时间需要 8 分钟。

 如有乱码,请

 

题目描述

Each of Farmer John's N (1 <= N <= 50,000) cows likes to graze in a certain part of the pasture, which can be thought of as a large one-dimeensional number line. Cow i's favorite grazing range starts at location S_i and ends at location E_i (1 <= S_i < E_i; S_i < E_i <= 100,000,000).

Most folks know the cows are quite selfish; no cow wants to share any of its grazing area with another. Thus, two cows i and j can only graze at the same time if either S_i >= E_j or E_i <= S_j. FJ would like to know the maximum number of cows that can graze at the same time for a given set of cows and their preferences.

Consider a set of 5 cows with ranges shown below:

... 1    2    3    4    5    6    7    8    9   10   11   12   13 ...  ... |----|----|----|----|----|----|----|----|----|----|----|----|----Cow 1:      <===:===>          :              :              :Cow 2: <========:==============:==============:=============>:Cow 3:          :     <====>   :              :              :Cow 4:          :              :     <========:===>          :Cow 5:          :              :     <==>     :              :

These ranges represent (2, 4), (1, 12), (4, 5), (7, 10), and (7, 8), respectively.

For a solution, the first, third, and fourth (or fifth) cows can all graze at the same time. If the second cow grazed, no other cows could graze. Also, the fourth and fifth cows cannot graze together, so it is impossible for four or more cows to graze.

约翰有N(1≤N≤50000)头牛,约翰的草地可以认为是一条直线.每只牛只喜欢在某个特定的范围内吃草.第i头牛喜欢在区间(Si,Ei)吃草,1≤Si<Ei≤1,000,000,00.

奶牛们都很自私,他们不喜欢和其他奶牛共享自己喜欢吃草的领域,因此约翰要保证任意

两头牛都不会共享他们喜欢吃草昀领域.如果奶牛i和奶牛J想要同时吃草,那么要满足:Si>=Ej或者Ei≤Sj.约翰想知道在同一时刻,最多可以有多少头奶牛同时吃草?

输入格式

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains the two space-separated integers: S_i and E_i

输出格式

* Line 1: A single integer representing the maximum number of cows that can graze at once.

输入输出样例

输入 #1复制
5 2 4 1 12 4 5 7 10 7 8
输出 #1复制
3
#include
#include
#include
#include
#include
#include
using namespace std;int n,t,ans=1;struct node{ int x,y;}a[50005];int read(){ int a=0,b=1; char ch=getchar(); while((ch<48||ch>57)&&ch!='-'){ ch=getchar(); } if(ch=='-'){ b=-1; ch=getchar(); } while(ch<48||ch>57){ ch=getchar(); } while(ch>47&&ch<58){ a=a*10+ch-48; ch=getchar(); } return a*b;}bool cmp(node x,node y){ return x.y
=t){ t=a[i].y; ans++; } } printf("%d",ans); return 0;}

  

转载于:https://www.cnblogs.com/xiongchongwen/p/11567003.html

你可能感兴趣的文章
2018-2019-2-20175332-实验四《Android程序设计》实验报告
查看>>
全栈12期的崛起之捡点儿有用的说说
查看>>
基础类型
查看>>
属性动画
查看>>
标识符
查看>>
Swift 常量&变量
查看>>
Sqli labs系列-less-4 这关好坑!!!
查看>>
路由跟踪工具0trace
查看>>
给大家分享一张CSS选择器优选级图谱 !
查看>>
Win7中不能调试windows service
查看>>
T-SQL触发器,限制一次只能删除一条数据
查看>>
boost库使用:vs2013下boost::container::vector编译出错解决
查看>>
通过httplib2 探索的学习的最佳方式
查看>>
理解运算符重载 4
查看>>
快来熟练使用 Mac 编程
查看>>
第二周
查看>>
断言简介
查看>>
Node.js 入门:Express + Mongoose 基础使用
查看>>
plsql使用,为什么可以能看见其他用户的表
查看>>
一步步教你轻松学奇异值分解SVD降维算法
查看>>