POJ 1064(二点)
1102 ワード
テーマリンク:http://poj.org/problem?id=1064
件名:
nつの棒の長さを与えるには、m本の長さが等しい棒を得る必要があります.短い棒でもいいです.一番長い棒の長さはいくらですか?
考え方:
直接に二点で解いてください.精度に注意してください.題目は二桁の小数を残して、直接に*100を数えて精度をコントロールできます.
件名:
nつの棒の長さを与えるには、m本の長さが等しい棒を得る必要があります.短い棒でもいいです.一番長い棒の長さはいくらですか?
考え方:
直接に二点で解いてください.精度に注意してください.題目は二桁の小数を残して、直接に*100を数えて精度をコントロールできます.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=10010;
int T,n,m;
int a[maxn];
int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
#endif
while(~scanf("%d%d",&n,&m)){
int low=1,high=-1;
double x;
for(int i=0;i<n;i++){
scanf("%lf",&x);
a[i]=(int)(x*100);
if(a[i]>high) high=a[i];
}
int ans=0;
while(low<=high){
int count=0;
int mid=(low+high)/2;
for(int i=0;i<n;i++){
count+=a[i]/mid;
}
if(count<m){
high=mid-1;
}
else if(count>=m){
low=mid+1;
ans=max(ans,mid);
}
}
printf("%.2lf
",(double)ans/100.0);
}
return 0;
}