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. split("\\.")是什么意思

    \\会转义成反斜杠,反斜杠本身就是转义符,所有就成了“\.”,在进行转义就是.,所以\\.实际上是“.”.在java.lang包中也有String.split()方法,与.net的类似,都是返回是一个 ...

  2. 洛谷 P1589 泥泞路

    题目描述 暴雨过后,FJ的农场到镇上的公路上有一些泥泞路,他有若干块长度为L的木板可以铺在这些泥泞路上,问他至少需要多少块木板,才能把所有的泥泞路覆盖住. 输入输出格式 输入格式: 第一行为正整数n( ...

  3. WOW.js 动画使用

    有的页面在向下滚动的时候,有些元素会产生细小的动画效果.虽然动画比较小,但却能吸引你的注意.比如刚刚发布的 iPhone 6 的页面(查看).如果你希望你的页面也更加有趣,那么你可以试试 WOW.js ...

  4. 如何用Python在10分钟内建立一个预测模型

    转载自:https://baijia.baidu.com/s?old_id=307995 最近,我从孙子(指<孙子兵法>——译者注)那里学到了一些策略:速度和准备 “兵之情主速,乘人之不及 ...

  5. [AHOI2005]病毒检测

    Description 科学家们在Samuel星球上的探险仍在继续.非常幸运的,在Samuel星球的南极附近,探险机器人发现了一个巨大的冰湖!机器人在这个冰湖中搜集到了许多RNA片段运回了实验基地.科 ...

  6. (转)生产者/消费者问题的多种Java实现方式

    参考来源:http://blog.csdn.net/monkey_d_meng/article/details/6251879/ 生产者/消费者问题的多种Java实现方式 实质上,很多后台服务程序并发 ...

  7. 自己写的MD5加密原码

    package com.wh.md5; import java.security.MessageDigest; import java.util.Arrays; /** * @author 王恒 * ...

  8. AngularJS 表单验证手机号(非必填)

    代码: <form ng-app="myApp" ng-controller="validateCtrl" name="myForm" ...

  9. Monkeyrunner介绍

    Monkeyrunner概述 Monkeyrunner是由Google开发.用于android系统的自动化测试工具,由android系统自带,存在于android sdk中(sdk:software ...

  10. UVA 10288 Coupons 彩票 (数学期望)

    题意:一种刮刮卡一共有n种图案,每张可刮出一个图案,收集n种就有奖,问平均情况下买多少张才能中奖?用最简的分数形式表示答案.n<=33. 思路:这题实在好人,n<=33.用longlong ...