【Codeforces875E】Delivery Club
来源:互联网 发布:canvas js库 编辑:程序博客网 时间:2024/06/05 08:57
首先二分答案,然后从后往前跑目的地维护可存在的区间。区间不存在或者开始点不在最终区间就不行,否则可以。
#include <bits/stdc++.h>#define gc getchar()#define ll long long#define N 100009#define mid (l+r>>1)using namespace std;int n,s,t,a[N];int read(){ int x=1; char ch; while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1; int s=ch-'0'; while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0'; return s*x;}bool check(int x){ if (abs(s-t)>x) return 0; int l=a[n]-x,r=a[n]+x; for (int i=n-1;i;i--) { int L=a[i]-x,R=a[i]+x; if (a[i]<l||a[i]>r) { L=max(L,l); R=min(R,r); } if (L>R) return 0; l=L,r=R; } return (s>=l&&s<=r||t>=l&&t<=r);}int main(){ n=read(),s=read(),t=read(); for (int i=1;i<=n;i++) a[i]=read(); int l=0,r=1000000000,ret=1000000000; while (l<=r) { if (check(mid)) ret=mid,r=mid-1; else l=mid+1; } printf("%d\n",ret); return 0;}
阅读全文
0 0
- 【Codeforces875E】Delivery Club
- [ ST表 ] Codeforces875E Delivery Club
- Codeforces 875E-Delivery Club
- [Codeforces 875E] Delivery Club
- Codeforces 875E Delivery Club 妙哉!
- [杂题 SET维护DP] Codeforces 875E. Delivery Club
- [SET维护DP] Codeforces #875E. Delivery Club
- Codeforces Round #441 (Div. 1, by Moscow Team Olympiad) E. Delivery Club
- Delivery
- 酒吧Club
- health club
- Fight Club
- fight club
- rycbar.club
- Delivery Completed
- Continuous Delivery
- Delivery SQL
- Content Delivery
- EXCEL数据筛选高级功能之条件区域
- 字符串截取
- StringUtils类中的isEmpty和isNotEmpty以及相关的
- ELK搭建(5.1版本)
- RPC框架与Netty框架
- 【Codeforces875E】Delivery Club
- 普惠金融是怎样发展壮大和红利释放的
- mysql存储过程小例
- 【python】python数据结构(五)——排序:直接选择排序
- Java
- ubuntu系统默认内核不支持Intel Dual Band Wireless-AC 3168无线网卡+ubuntu升级内核:遇到的问题及解决办法
- jQueryEasyui:导出Word
- git 拉取远程指定分支 pull本地不存在的分支
- Linq之Lambda表达式初步认识