[杂题 SET维护DP] Codeforces 875E. Delivery Club
来源:互联网 发布:华为服务器安装ubuntu 编辑:程序博客网 时间:2024/06/05 01:52
考虑二分答案
只要能检验答案能不能小于
令
那么
这东西要set维护下就好了…
#include <cstdio>#include <iostream>#include <algorithm>#include <set>#include <cmath>using namespace std;const int N=100010;int n,a[N];set<int> S;inline bool check(int x){ if(abs(a[1]-a[2])>x) return false; S.clear(); S.insert(a[1]); for(int i=3;i<=n;i++){ S.insert(a[i-1]); while(!S.empty() && abs(*S.begin()-a[i])>x) S.erase(S.begin()); while(!S.empty() && abs(*S.rbegin()-a[i])>x) S.erase(*S.rbegin()); if(S.empty()) return false; } return true;}int main(){ scanf("%d%d%d",&n,&a[1],&a[2]); for(int i=3;i<=n+2;i++) scanf("%d",&a[i]); n+=2; int L=0,R=1000000000,mid,ans; while(L<=R) check(mid=L+R>>1)?R=(ans=mid)-1:L=mid+1; printf("%d\n",ans); return 0;}
阅读全文
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)
- OkHttp3源码解析03-缓存
- 跟测试对齐第一现场很重要
- BZOJ 1703 [Usaco2007 Mar]Ranking the Cows 奶牛排名 Floyd+bitset
- Xcode9学习笔记10
- uva 1220 树的最大独立集和唯一性的判断
- [杂题 SET维护DP] Codeforces 875E. Delivery Club
- TCP三次握手和四次挥手
- 2017.10.6 BJOI2015 bzoj4338 糖果
- 关于python with的用法
- PAT 甲级 1113. Integer Set Partition (25)
- linux的压缩解压
- linux 10系统日志
- 浅谈 Web 缓存
- 082 广义积分总结区间无限及区间有限