题目链接
很简单的二分答案,为什么去年会做不出来呢。。。。哎。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int maxn = 3e5+10;
long long save[maxn];
long long ice[maxn];
int k,n;
bool check(int x){
int i,j;
int l = 1;
long long *p;
for(i=1;i<=x;i++){
ice[i] = 0;
}
for(i=1;i<=k;i++){
for(j=1;j<=x;j++){
p = lower_bound(save+l, save+1+n, 2*ice[j]);
if(p == save+n+1){
return false;
}
ice[j] = *p;
l = (p - save)+1;
}
}
return true;
}
int main(){
int t,i;
int rnd = 1;
scanf("%d",&t);
while(t--){
printf("Case #%d: ",rnd++);
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++){
scanf("%lld",save+i);
}
sort(save+1,save+1+n);
int l = 0, r = n, mid;
while(l+1<r){
mid = (l+r)/2;
if(check(mid)){
l = mid;
}else{
r = mid - 1;
}
}
if(check(r)){
printf("%d\n",r);
}else{
printf("%d\n",l);
}
}
return 0;
}