Description

Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it.

To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible.

The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter, and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled.

You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.

 

Input

The input consists of several testcases. The first line of each testcase contains two integer numbers N and K, separated by a space. N (1 ≤ N ≤ 10000) is the number of cables in the stock, and K (1 ≤ K ≤ 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 centimeter and at most 100 kilometers in length. All lengths in the input are written with a centimeter precision, with exactly two digits after a decimal point.

The input is ended by line containing two 0's.

 

Output

For each testcase write to the output the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point.

If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output must contain the single number "0.00" (without quotes).

 

Sample Input

4 11
8.02
7.43
4.57
5.39
0 0
 

Sample Output

2.00
 
输入电缆的个数n,和要分的份数k,求出所有电缆的长度和sum,在区间[0,sum/k]内用二分法求出最大的长度。
 #include<cstdio>
#include<math.h>
#define st 1e-8
double a[];
int k,n;
int f(double x)
{
int su=;
for(int i = ; i < n ; i++)
{
su+=(int)(a[i]/x); //括号不能少
}
return su;
}
int main()
{ double sum;
while(scanf("%d%d",&n,&k) && (n+k))
{
sum=;
for(int i = ; i < n ; i++)
{
scanf("%lf",&a[i]);
sum+=a[i];
}
sum=sum/k;
double l=,r=sum,mid;
while(fabs(l-r)>st)
{
mid=(l+r)/;
if(f(mid) >= k)
l=mid;
else
r=mid;
}
printf("%.2f\n",l);
}
}

Cable master 求电缆的最大长度(二分法)的更多相关文章

  1. poj1064 Cable master(二分)

    Cable master 求电缆的最大长度(二分法)   Description Inhabitants of the Wonderland have decided to hold a region ...

  2. POJ 1064 Cable master (二分法+精度控制)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65358   Accepted: 13453 De ...

  3. Cable master(二分-求可行解)

    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...

  4. hdu 1551 Cable master (二分法)

    Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. 二分法的应用:POJ1064 Cable master

    /* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...

  6. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  7. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

  8. poj 1064 Cable master【浮点型二分查找】

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29554   Accepted: 6247 Des ...

  9. Cable master(好题,二分)

    Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

随机推荐

  1. redis的安装(图文详解)

    我这里,搭建在 继续

  2. 转:从《The C Programming Language》中学到的那些编程风格和设计思想

    这儿有一篇写的很好的读后感:http://www.cnblogs.com/xkfz007/articles/2566424.html   读书不是目的,关键在于思考.   很早就在水木上看到有人推荐& ...

  3. 浅谈Java中static作用--转

    static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...

  4. Java异常概念

  5. CentOS 6.9:MySQL Daemon failed to start.

    [root@Server_1 12:02:58 ~ 25]#service mysqld start MySQL Daemon failed to start.Starting mysqld: [ro ...

  6. CentOS6.5下中文输入法的相关问题

    问题.点击Input Method Preferences没反应. 首先执行 yum install "@Chinese Support" yum install -yibus-t ...

  7. 在input标签里只能输入数字

    <input type='text' onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,''); ...

  8. 外文翻译 《How we decide》被情感愚弄 第一节

    本节为第三章的起始. 书的导言 本节阅读感言:情感系统脱离控制的后果是毁灭性的. Ann Klinestiver 在一所高中做英文老师,她被诊断为患帕金森综合症.在课堂上,当她正准备和学生们谈及一些莎 ...

  9. spring boot jar启动

    1.依赖包输出 记得禁用热加载 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactI ...

  10. 证明碰撞集问题(Hitting Set)是NP-complete

    证明碰撞集问题(Hitting Set)是NP-complete Problem In the HITTING SET problem, we are given a family of sets { ...