线段的重叠

 1 #include <bits/stdc++.h>
 2 #define _xx ios_base::sync_with_stdio(0);cin.tie(0);
 3 using namespace std;
 4 typedef long long ll;
 5 struct node
 6 {
 7     int s, e;
 8 } a[50005];
 9 bool operator < (const node& t1, const node& t2)
10 {
11     return t1.s < t2.s;
12 }
13 int main()
14 {_xx
15     int n, ans = 0;
16     cin >> n;
17     for(int i = 1; i <= n; i++) cin >> a[i].s >> a[i].e;
18     sort(a + 1, a + n + 1);
19     int lmost = 0;
20     for(int i = 1; i <= n; i++)
21     {
22         if(lmost <= a[i].e) ans = max(ans, lmost - a[i].s);
23         else ans = max(ans, a[i].e - a[i].s);
24         lmost = max(lmost, a[i].e);
25     }
26     cout << ans << endl;
27     return 0;
28 }
View Code

 

posted on 2017-04-15 17:28 NWU_ACM 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/NWUACM/p/6714942.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值