[SET维护DP] Codeforces #875E. Delivery Club
来源:互联网 发布:杨紫宁丹琳 知乎 编辑:程序博客网 时间:2024/06/05 03:46
好题。首先不难想到二分答案。验证就是写出状态
怎么优化呢? 可以发现这个
所以我们就可以用
复杂度
#include<cstdio>#include<cmath>#include<set>#include<algorithm>using namespace std;const int maxn=200005;set<int> S; int n,a[maxn],ans;bool check(int lim){ if(abs(a[1]-a[2])>lim) return false; S.clear(); S.insert(a[1]); for(int i=3;i<=n+2;i++){ S.insert(a[i-1]); while(!S.empty()&&abs(a[i]-(*S.begin()))>lim) S.erase(*S.begin()); while(!S.empty()&&abs(a[i]-(*S.rbegin()))>lim) S.erase(*S.rbegin()); if(S.empty()) return false; } return true;}int main(){ freopen("cf875E.in","r",stdin); freopen("cf875E.out","w",stdout); scanf("%d%d%d",&n,&a[1],&a[2]); for(int i=3;i<=n+2;i++) scanf("%d",&a[i]); int L=0,R=1e9; while(L<=R){ int mid=(L+R)>>1; if(check(mid)) R=mid-1, ans=mid; else L=mid+1; } check(1); printf("%d\n",ans);}
阅读全文
0 0
- [杂题 SET维护DP] Codeforces 875E. Delivery Club
- [SET维护DP] Codeforces #875E. Delivery Club
- Codeforces 875E-Delivery Club
- [Codeforces 875E] Delivery Club
- Codeforces 875E Delivery Club 妙哉!
- Codeforces Round #441 (Div. 1, by Moscow Team Olympiad) E. Delivery Club
- Mishap in Club--codeForces 245E--贪心
- CodeForces 245E Mishap in Club
- 【Codeforces875E】Delivery Club
- Codeforces 635E Package Delivery【贪心】
- [ ST表 ] Codeforces875E Delivery Club
- Codeforces Round #227 (Div. 2)---E. George and Cards(贪心, 树状数组+set维护, 好题!)
- 【dp】codeforces 83E
- codeforces-731E-dp
- Codeforces 748E dp
- Codeforces 722E [DP]
- Codeforces 416E DP
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
- 深度学习概述<一>深度学习知识结构介绍
- AVLTree 学习
- Golang程序结构概述
- Ubantu安装
- JavaScript笔记(touch事件)
- [SET维护DP] Codeforces #875E. Delivery Club
- 文章标题
- asp.net导出Excel乱码的原因及解决方法
- 兼容性测试的测试点
- ant复制
- Java线程面试题 Top 50
- uva10336
- cocos2d-x 3.0对label的改进
- C/C++ key concepts