51nod 1091 线段的重叠(贪心)
来源:互联网 发布:华为手机数据恢复中心 编辑:程序博客网 时间:2024/06/06 10:01
1091 线段的重叠
基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
收藏
关注
X轴上有N条线段,每条线段包括1个起点和终点。线段的重叠是这样来算的,[10 20]和[12 25]的重叠部分为[12 20]。
给出N条线段的起点和终点,从中选出2条线段,这两条线段的重叠部分是最长的。输出这个最长的距离。如果没有重叠,输出0。
Input
第1行:线段的数量N(2 <= N <= 50000)。第2 - N + 1行:每行2个数,线段的起点和终点。(0 <= s , e <= 10^9)
Output
输出最长重复区间的长度。
Input示例
51 52 42 83 77 9
Output示例
4
相关问题
不重叠的线段
10
const int maxn=5e4+10;struct node{ int x,y; bool operator<(const node & a)const { if(x!=a.x) return x<a.x; return y>a.y; }}a[maxn];int main(){ ios::sync_with_stdio(false); int n,k,ans,pre; while(cin>>n) { ans=0,pre=0; for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y; sort(a,a+n); for(int i=0;i<n;i++) { ans=max(ans,min(pre,a[i].y)-a[i].x); pre=max(pre,a[i].y); } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- 51nod 1091 线段的重叠(贪心)
- 51nod 1091 线段的重叠 贪心
- 51nod 1091 线段的重叠 贪心
- 贪心-51nod 1091 线段的重叠
- 51nod 1091 线段的重叠 (贪心)
- 51nod 1091 线段的重叠(贪心)
- 51Nod 1091 线段的重叠 贪心
- 51nod 1091 线段的重叠 (贪心)
- 51Nod 1091 线段的重叠 (贪心)
- 51nod 1091 线段的重叠(贪心思维)
- 51nod 1091 线段的重叠(贪心)
- 51nod 1091 线段的重叠(贪心)
- 51nod 1091 线段的重叠(贪心)
- 【51nod】-1091 线段的重叠(贪心)
- 51nod 线段的重叠(贪心)
- 51nod oj 1091 线段的重叠 【贪心】
- 51Nod 1091 线段的重叠 (区间贪心
- 51nod 1133 不重叠的线段(贪心)
- python 将文本内容转为字典
- 设置tablayout tab
- Unity的NGUI插件的HUD Text插件血条数值的显示
- android的隐式意图
- 一致性HASH算法详解
- 51nod 1091 线段的重叠(贪心)
- 2017 ACM/ICPC Asia Regional Shenyang Online 1008 transaction transaction transaction
- 第4周项目1- 建立单链表
- 使用mapper接口改进持久层开发————6
- 【Unity】Fly Bird(游戏实战)(1)
- 简易日历 2
- zhaoshangwangke面试题
- 数据结构第二周项目--体验复杂度之汉诺塔
- 【Android】直接构造BpBinder(handle)进行binder通信猜想