7 条题解
-
1魔阴身重度依赖 (lijunting) LV 7 @ 2024-12-1 19:41:25
#include<bits/stdc++.h> using namespace std; const int N = 1e5+10; int n,m,l,r,a[N],ans; bool v[10005]; bool check(int mid){ int sum = 1; int last = a[1]; for(int i = 2;i <= n;i++){ if(last + mid<=a[i]){ last = a[i]; sum++; } } return sum >= m; } int main(){ cin >> n >> m; for(int i = 1;i <= n;i++) cin >> a[i]; sort(a+1,a+n+1); l = 1; r = a[n] - a[1]; while(l<=r){ int mid = (l+r)>>1; if(check(mid)){ ans = mid; l = mid+1; } else r = mid - 1; } cout << ans; return 0; }
-
12024-12-1 18:45:02@
```#include <bits/stdc++.h> using namespace std; #define LL long long #define ull unsigned long long const int N=1e5+10; const int INF=0x3f3f3f3f; const double pi=3.1416; int n,m,a[N],l,r,ans; bool check(int mid){ int sum=1; int last=a[1]; for(int i=2;i<=n;i++){ if(last+mid<=a[i]){ last=a[i]; sum++; } } return sum>=m; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); l=1; r=a[n]-a[1]; while(l<=r){ int mid=(l+r)>>1; if(check(mid)){ ans=mid; l=mid+1; }else{ r=mid-1; } } cout<<ans<<endl; return 0; }
-
02024-9-17 15:57:43@
/* int %o/%lo(八进制) %d/%i/%ld/%li(十进制) %x/%lx(十六进制)[如标名为o/lo/d/i/lo/li/x/lx即输出为八进制/十进制/十六进制] longlong %lld float %f/%e double %lf/%le char %c char[] %s 'a'=97 'z'=122 'A'=65 'Z'=90 '0'=48 '9'=57 */ #include <iostream> #include <iomanip> #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #include <ctime> #include <limits> #include <assert.h> #include <stdlib.h> using namespace std; #define LL long long #define ull unsigned long long const int N=1e5+10; const int INF=0x3f3f3f3f; const double pi=3.1416; int n,m,a[N],l,r,ans; bool check(int mid){ int sum=1; int last=a[1]; for(int i=2;i<=n;i++){ if(last+mid<=a[i]){ last=a[i]; sum++; } } return sum>=m; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); l=1; r=a[n]-a[1]; while(l<=r){ int mid=(l+r)>>1; if(check(mid)){ ans=mid; l=mid+1; }else{ r=mid-1; } } cout<<ans<<endl; return 0; }
-
02024-7-31 9:55:06@
#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 = 1,r,L,n,k,a[N];
bool check(int mid){
int sum = 1;
int last = a[1];
for(int i = 2;i<=n;i++){
if(a[i] - last >= mid){
sum ++;
last = a[i];
}
}
return sum >= k;
} int main(){
cin>>n>>k;
for(int i = 1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
r = a[n] - a[1];
while(l<=r){
int mid = l + r >>1;
if(check(mid)){
ans = mid;
l = mid + 1;
}
else
r = mid - 1;
}
cout<<ans;
}
-
02024-6-2 18:01:15@
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; int n,m,a[N],l,r,ans; bool check(int mid){ int sum=1,l=a[1]; for(int i=2;i<=n;i++){ if(a[i]>=l+mid){ sum++; l=a[i]; } } return sum>=m; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); l=1; r=a[n]; while(l<=r){ int mid=l+r>>1; if(check(mid)){ ans=mid; l=mid+1; }else{ r=mid-1; } } cout<<ans; return 0; }
-
02024-6-2 18:00:26@
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m; int a[N], l, r, mid, ans; bool check(int mid){ int sum = 1; int last = a[1]; for(int i = 2 ; i <= n ; i++){ if(a[i] >= last + mid){ sum++; last = a[i]; } } return sum >= m; } int main(){ cin >> n >> m; for(int i = 1 ; i <= n ; i++) cin >> a[i]; sort(a + 1 , a + n + 1); l = 1; r = a[n]; while(l <= r){ int mid = l + r >> 1; if(check(mid)){ ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << endl; return 0; }
-
02024-6-2 17:59:29@
#include<iostream> #include<algorithm> #include<iomanip> #include<cstring> #include<string> #include<cmath> #include<queue> #include<set> using namespace std; const int N=1e5+10; const int INF=0x3f3f3f3f; int n,m,a[N],l,r,ans; bool check(int mid) { int sum=1,last=a[1]; for(int i=2;i<=n;i++) { if(a[i]-last>=mid) { sum++; last=a[i]; } } return sum>=m; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); l=1,r=a[n]; while(l<=r) { int mid=l+r>>1; if(check(mid)) { ans=mid; l=mid+1; } else r=mid-1; } cout<<ans; return 0; }
- 1
信息
- ID
- 357
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 7
- 标签
- 递交数
- 404
- 已通过
- 100
- 上传者