SCUT Training 20170920 Problem J
来源:互联网 发布:桃源网络硬盘登录APP 编辑:程序博客网 时间:2024/06/05 11:16
原题:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1091
思路:
原本我犯懒打算暴力,结果最后一个测试点TLE了。贪心其实是最好的
源代码:
代码是某个大佬的源码,这种红黑树的操作我还不太会用,反正比我的方法好很多
#include <cstdio> #include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 50010;typedef long long ll;struct Seg{ ll l, r; Seg() {} Seg(ll t_l,ll t_r):l(t_l),r(t_r){} bool operator<(const Seg &s) const { if(l == s.l) { return r > s.r; } return l < s.l; }}segs[maxn];inline ll max(ll a,ll b){ return a>b?a:b;}inline ll min(ll a,ll b){ return a<b?a:b;}inline void swap(ll &a,ll &b) { ll t=a; a=b; b=t; return;}int main() { int n; int ans = 0; Seg s; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld %lld",&segs[i].l,&segs[i].r); if (segs[i].l>segs[i].r) { swap(segs[i].l,segs[i].r); } } sort(segs+1,segs+n+1); s.l=segs[1].l,s.r=segs[1].r; for (int i=2;i<=n;++i) { ans=max(ans,min(s.r,segs[i].r)-max(s.l,segs[i].l)); if(s.r<segs[i].r) { s=segs[i]; } } cout<<ans<<endl; return 0;}
阅读全文
0 0
- SCUT Training 20170920 Problem J
- SCUT Training 20170913 Problem J
- SCUT Training 20170920 Problem A
- SCUT Training 20170920 Problem B
- SCUT Training 20170920 Problem C
- SCUT Training 20170920 Problem D
- SCUT Training 20170920 Problem E
- SCUT Training 20170920 Problem F
- SCUT Training 20170920 Problem G
- SCUT Training 20170920 Problem H
- SCUT Training 20170920 Problem I
- SCUT Training 20170920 Problem K
- SCUT Training 20170920 Problem L
- SCUT Training 20170920 Problem M
- SCUT Training 20170920 Problem N
- SCUT Training 20170920 Problem O
- SCUT Training 20170920 Problem P
- SCUT Training 20170913 Problem A
- 項目傳到服務器 參數亂碼
- 决策树vs行为树
- Supervised Learning Model-Classification Learning
- PhpStrom,RubyMine,WebStorm,PyCharm注册机
- Supervised Learning Model Regression Prediction
- SCUT Training 20170920 Problem J
- 多版本下python的pip区分问题
- Tensorflow报错:AttributeError: 'module' object has no attribute 'scalar_summary'
- CGAL 4.11 版 win10-vs2015-64bit 编译与开发关键点指南
- JVM调优总结(二)-一些概念
- 139. Word Break
- linux之 LVM扩容
- 携程笔试——二叉树遍历
- android ble : 一(蓝牙门禁的ble通讯完整流程)