2 条题解
-
0zxj (zhangxuanju) LV 8 @ 2024-11-5 19:39:12
#include<bits/stdc++.h> using namespace std; const int N = 1e6 +10; const int INF=0x3f3f3f; int ans,l,r,L,n,k,a[N]; bool check(int mid){ int sum = 0; for(int i = 2;i<=n;i++) sum+=(a[i] - a[i-1] - 1) / mid; return sum <= k; } int main(){ cin>>L>>n>>k; for(int i = 1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); r = a[n] - 1; while(l<=r){ int mid = l + r >>1; if(check(mid)){ ans = mid; r = mid - 1; } else l = mid + 1; } cout<<ans; }
-
02024-7-31 9:42:11@
#include<iostream>
#include<stack>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 1e6 +10;
const int INF=0x3f3f3f;
int ans,l,r,L,n,k,a[N];
bool check(int mid){
int sum = 0;
for(int i = 2;i<=n;i++)
sum+=(a[i] - a[i-1] - 1) / mid;
return sum <= k;
}
int main(){
cin>>L>>n>>k;
for(int i = 1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
r = a[n] - 1;
while(l<=r){
int mid = l + r >>1;
if(check(mid)){
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
cout<<ans;
}
- 1
信息
- ID
- 1276
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 217
- 已通过
- 22
- 上传者