标签:int ble cto dig tmp signed lang head printf
跳石头
简单的二分答案,贪心地判断解
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define U(i,u) for(register int i=head[u];i;i=nxt[i])
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define per(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> PII;
typedef vector<int> VI;
template<class T> inline void read(T &x){
x=0;char c=getchar();int f=1;
while(!isdigit(c)){if(c==‘-‘)f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();}x*=f;
}
template<class T> inline void cmin(T &x, T y){x=x<y?x:y;}
template<class T> inline void cmax(T &x, T y){x=x>y?x:y;}
const int N=500001;
int di,n,m,su[N];
bool check(int an){
int tmp=0;rep(i,0,n){
int j=i+1;
while(su[j]-su[i]<an&&j<=n)++j,++tmp;
i=j-1;
if(tmp>m)return 0;
}
return 1;
}
int main(){
read(di);read(n);read(m);su[n+1]=di;
rep(i,1,n)read(su[i]);
int l=0,r=su[n+1];
while(r-l>=3){
int mid=(r+l)>>1;
if(check(mid))l=mid;
else r=mid-1;
}
per(i,r,l){
if(check(i)){
printf("%d",i);
return 0;
}
}
return 0;
}
标签:int ble cto dig tmp signed lang head printf
原文地址:https://www.cnblogs.com/hangzz/p/13381856.html