#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,d[500005],ans;
ll L;
ll check(ll mid){
ll cnt,qd=0;
for(ll i=1;i<=n;i++){
if(d[i]-d[qd]>=mid)qd=i;
else cnt++;
}
return cnt;
}
int main(){
cin>>L>>n>>m;
for(ll i=1;i<=n;i++)cin>>d[i];
n++;d[n]=L;
ll l=0,r=L,mid,x;
while(l<=r){
ll mid=(l+r)/2;
x=check(mid);
if(x>m)r=mid-1;
else{
ans=mid;l=mid+1;
}
}
cout<<ans<<endl;
return 0;
}
1 个赞
不会格式化
1 个赞
抱歉
1 个赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,d[500005],ans;
ll L;
ll check(ll mid){
ll cnt,qd=0;
for(ll i=1;i<=n;i++){
if(d[i]-d[qd]>=mid)qd=i;
else cnt++;
}
return cnt;
}
int main(){
cin>>L>>n>>m;
for(ll i=1;i<=n;i++)cin>>d[i];
n++;d[n]=L;
ll l=0,r=L,mid,x;
while(l<=r){
ll mid=(l+r)/2;
x=check(mid);
if(x>m)r=mid-1;
else{
ans=mid;l=mid+1;
}
}
cout<<ans<<endl;
return 0;
}
帮你格式化好了虽然这题我也不会
谢了