51nod 1091 线段的重叠
来源:互联网 发布:淘宝卖家自动回复语 编辑:程序博客网 时间:2024/06/06 10:53
题目链接:传送门
是不重叠线段简单版,这个只用对开始的端点进行大小排序,每次记录最后面的端点的位置r
如果当前的线段的右端点小于r,则这个线段被另一个大的线段包住,否则则要算到这个线段的左端点到这个r,计算长度并且更新r就行了
代码如下:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define N 50010struct rng{ int s,e;}t[N];bool cmp(rng a,rng b){ if(a.s<b.s) return 1; if(a.s==b.s&&a.e<=b.e) return 1; return 0;}int main(){ int i,j,n,m,k; while(scanf("%d",&n)!=EOF){ for(i=1;i<=n;i++) cin>>t[i].s>>t[i].e; sort(t+1,t+1+n,cmp); int r=t[1].e; int res=0; // for(i=1;i<=n;i++) cout<<t[i].s<<t[i].e<<endl; for(i=2;i<=n;i++){ if(t[i].s>=r){ r=t[i].e; continue; } if(t[i].e>=r){ int x=r-t[i].s; if(x>res) res=x; r=t[i].e; continue; } if(t[i].e<=r){ int x=t[i].e-t[i].s; if(x>res) res=x; continue; } } cout<<res<<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 线段的重叠
- 51 NOD 1091 线段的重叠
- 51Nod 1091 线段的重叠
- 51 nod 1091 线段的重叠
- 51Nod-1091 线段的重叠【排序】
- 51Nod 1091 线段的重叠
- 51nod 1091 线段的重叠
- SQLITE3操作函数
- HashMap浅析
- Mysql集群的HA原理及配置指南之字段冲突修复(四)
- 科学史上最伟大的十位单身科学家
- Bootstrap手机端下拉菜单(铺满)
- 51nod 1091 线段的重叠
- PHP基础
- JAVA全集-03-面向对象编程
- iOS百度地图界面切换,滑动卡顿
- BroadcastReceiver
- BSS段为什么需要初始化
- react native极光推送全程教程android和ios
- 【JZOJ4884】【NOIP2016提高A组集训第12场11.10】图的半径
- C++ P1379 八数码难题