[交互题] APIO2016 Gap
来源:互联网 发布:证券公司怎么样知乎 编辑:程序博客网 时间:2024/06/04 23:28
看题解
l1. 询问[0,10^18],得到最小值t1,最大值s1,代价为N+1
l2. 设L = [(s1-t1)/N](向上取整),由于最终的答案一定会大于等于平均值L,所以当我们考虑一段长度为L的区间时,只用关心区间内的最小值和最大值即可。
l所以询问[t1+1,t1+L],[t1+L+1,t1+2L]...,总共询问不超过N次,覆盖总点数为N-2(去掉t1和s1)。
总共花费代价:N+1+N+N-2 = 3N-1#include "gap.h"#include<algorithm>using namespace std;typedef long long ll;const int iN=200005;ll tot,a[iN];ll findGap(int T, int N){ ll minv,maxv; MinMax(0,(ll)1e18,&minv,&maxv); tot=0; if (T==1){ a[1]=minv; a[N]=maxv; for (int i=2,j=N-1;i<=j;i++,j--){ MinMax(minv+1,maxv-1,&minv,&maxv); a[i]=minv; a[j]=maxv;} tot=N; } else{ ll L=(maxv-minv-1)/N+1; ll Min=minv,Max=maxv; a[++tot]=Min; for (ll i=Min;i+1<=Max-1;i=i+L){ MinMax(i+1,min(i+L,Max-1),&minv,&maxv); if (maxv==-1 && minv==-1) continue; a[++tot]=minv; a[++tot]=maxv; } a[++tot]=Max; } ll ans=0; for (int i=1;i<tot;i++) ans=max(ans,a[i+1]-a[i]); return ans;}
0 0
- [交互题] APIO2016 Gap
- UOJ#206. 【APIO2016】Gap
- UOJ 206 [APIO2016]Gap
- 【APIO2016】uoj206 Gap
- [UOJ#206][Apio2016]Gap(分块+数学相关)
- Gap
- GAP
- APIO2016游记
- APIO2016游记
- APIO2016总结
- Apio2016 游记
- APIO2016总结
- APIO2016 题解
- APIO2016滚粗记
- [Leetcode新题] Maximum Gap
- CTSC2016&&APIO2016爆零记
- ctsc&apio2016 总结
- 【bzoj4584】[Apio2016]赛艇 dp
- 阿里云-挂载盘分区和格式化步骤
- android基础_第十天
- Installation failed with message:INSTALL_CANCELED_BY_USER
- 集成Reactive Cocoa
- Ubuntu 16.04 安装搜狗拼音输入法
- [交互题] APIO2016 Gap
- c# 界面假死
- 如何用git将项目代码上传到github
- shell中的cut命令
- Python之函数
- 日志:slf4j+logback日志生成
- unix环境高级编程--线程同步
- nodejs ssh2 基本功能的封装
- C實踐項目4.5—座標轉換