贪心-51nod 1091 线段的重叠
来源:互联网 发布:js手写bind实现原理 编辑:程序博客网 时间:2024/05/17 01:55
思路:
对最短点从小到大排序。
每次维护端点在最右侧的值,每次用上次最大的右侧减去当前的左端点,记录最大值。
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;struct node{ int x,y;}a[500005];int cmp(node t1,node t2){ return t1.x<t2.x;}int main(){ int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y; sort(a+1,a+1+n,cmp); int last=0; int maxx=0; for(int i=1;i<=n;i++) { if(a[i].y<last) maxx=max(a[i].y-a[i].x,maxx); else { maxx=max(last-a[i].x,maxx); last=a[i].y; } } cout<<maxx<<endl; return 0;}
0 0
- 51nod 1091 线段的重叠(贪心)
- 51nod 1091 线段的重叠 贪心
- 51nod 1091 线段的重叠 贪心
- 贪心-51nod 1091 线段的重叠
- 51nod 1091 线段的重叠 (贪心)
- 51nod 1091 线段的重叠(贪心)
- 51Nod 1091 线段的重叠 贪心
- 51nod 线段的重叠(贪心)
- 51nod 1091 线段的重叠 (贪心)
- 51nod oj 1091 线段的重叠 【贪心】
- 51Nod 1091 线段的重叠 (贪心)
- 51nod 1091 线段的重叠(贪心思维)
- 51Nod 1091 线段的重叠 (区间贪心
- 51nod 1091 线段的重叠(贪心)
- 51nod 1091 线段的重叠(贪心)
- 51nod 1091 线段的重叠(贪心)
- 【51nod】-1091 线段的重叠(贪心)
- 51NOD 1091 线段重叠 51 NOD 1133不重叠线段 贪心
- opencv技术访问图像中的像素
- C# WebBrowser强制在本窗口打开,禁止在新窗口打开
- Makefile 中:= ?= += =的区别
- Tyvj P1354 日历
- springmvc和struts2的区别
- 贪心-51nod 1091 线段的重叠
- golang
- decode图片时BitmapFactory.Options中的inDensity和inTargetDensity
- 运动时间
- Sublime Text 2使用教程一
- angular.js学习(2)--filter
- hdu ---2007做题笔记(c++)
- 一步一步DIY jQuery库2-使用es6模块化
- BOM(二)间歇调用和超时调用、BOM其他主要对象