📄 cable.cpp
字号:
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
FILE *inp,*outp;
long p1,p2,p3,n,m,i,a[10010];
double x;
bool King(long p3){
if (p3==0) return true;
long sum=0;
for (long i=1;i<=n;i++)
sum+=a[i]/p3;
return sum>=m;
}
main(){
inp=fopen("cable.in","r");assert(inp);
outp=fopen("cable.out","w");assert(outp);
fscanf(inp,"%ld%ld",&n,&m);
for (i=1;i<=n;i++){
fscanf(inp,"%lf",&x);a[i]=long(x*100);
}
p1=0;p2=10000000;
while (p1+1<p2){
p3=(p1+p2)/2;
if (King(p3)) p1=p3;else
p2=p3;
}
if (King(p2)) fprintf(outp,"%ld.%ld%ld\n",p2/100,(p2%100)/10,p2%10);
fprintf(outp,"%ld.%ld%ld\n",p1/100,(p1%100)/10,p1%10);
fclose(outp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -