传送门

思路:

  二分跳跃的最短距离 mid 。暴力判断如果有两个石头直接的距离小于 mid ,就把这个石头拿走。如果拿走的石头数目 cnt ≤ m,说明二分的答案可行,ans = mid,接着二分更短的跳跃距离。

Code:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
#define lck_max(a,b) ((a)>(b)?(a):(b))
#define lck_min(a,b) ((a)<(b)?(a):(b))
typedef long long LL;
const int maxn=5e5+;
LL d,n,m;
LL t[maxn];
inline LL read()
{
LL kr=,xs=;
char ls;
ls=getchar();
while(!isdigit(ls))
{
if(!(ls^))
kr=-;
ls=getchar();
}
while(isdigit(ls))
{
xs=(xs<<)+(xs<<)+(ls^);
ls=getchar();
}
return xs*kr;
}
inline void out(LL xs)
{
if(!xs) {putchar(); return;}
if(xs<) putchar('-'),xs=-xs;
int kr[],ls=;
while(xs) kr[++ls]=xs%,xs/=;
while(ls) putchar(kr[ls]+),ls--;
}
LL cnt,i,now;
inline bool check(LL u)
{
cnt=,i=,now=;
while(i<=n)
{
i++;
if(t[i]-t[now]<u)
cnt++;
else
now=i;
}
if(cnt>m)
return false;
else
return true;
}
LL ans;
inline void query(LL l,LL r)
{
while(l<=r)
{
LL mid=l+r>>;
if(check(mid))
ans=mid,l=mid+;
else
r=mid-;
}
}
int main()
{
d=read();n=read();m=read();
for(LL i=;i<=n;i++)
t[i]=read();
t[n+]=d;//终点到起点的距离。
query(,d);
out(ans),putchar('\n');
return ;
}

最新文章

  1. 利用AOP写2PC框架(一)
  2. CI模板加载css和js
  3. G-nav-01
  4. thinkphp 初始配置
  5. JavaScript【面向对象】-静态方法-私有方法-公有方法-特权方法
  6. LINUX下mysql的大小写是否区分设置 转
  7. 1.3 selenium IDE录制脚本转换为其他代码格式
  8. HTML 5 Web 存储、应用程序缓存、Web Workers
  9. C# GDI绘图之——画笔和画刷
  10. Centos 6.7 KVM下安装windows 7系统
  11. ADC采样工作原理详解
  12. vivado中如何使用chipscope
  13. [NOIP2018]OI之旅的中转站
  14. awk技巧(如取某一行数据中的倒数第N列等)
  15. mac下搭建node+koa2项目
  16. ArcGIS教程:树状图
  17. 聊下图片滤镜,手机上的,lookup table(颜色查找表
  18. DDA_为微分绘制直线算法
  19. tomcat 8 加 struts2的 java.lang.NoSuchFieldException: resourceEntries
  20. php解决时间超过2038年

热门文章

  1. python3.6安装docx模块
  2. Hadoop组件
  3. 取模性质,快速幂,快速乘,gcd和最小公倍数
  4. myeclipse2017下载安装与破解详细教程
  5. zlib简单使用说明(转)
  6. Oauth2.0安全问题浅谈
  7. linux 笔记 第一天
  8. Canvas Snippets
  9. Excel坐标自动在AutoCad绘图_3
  10. IT题库5-并发和并行