POJ 1064 Cable master
……
精度各种锅
转了int再判终于对了
还有cin cout 被卡
伤心
#include <cstdio>
using namespace std;
const int MAXN=10011;
double input;
int N, K;
int Num[MAXN];
int Left, Right, Mid;
bool Test(int k){
int c=0;
for(int i=1;i<=N;++i){
c+=Num[i]/k;
}
return c>=K;
}
int main(){
while(scanf("%d%d", &N, &K)!=EOF){
for(int i=1;i<=N;++i){
scanf("%lf", &input);
Num[i]=(int)(input*100.0);
}
Left=0;Right=0;
for(int i=1;i<=N;++i) if(Num[i]>Right) Right=Num[i];
while(Left<Right){
Mid=(Left+Right)>>1;
if(Test(Mid+1)) Left=Mid+1;
else Right=Mid;
}
Mid=(Left+Right)>>1;
printf("%d.%d%d\n", Mid/100, (Mid/10)%10, Mid%10);
}
return 0;
}