Cable master

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1428    Accepted Submission(s): 522

Problem 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
 
Source
 
Recommend
LL   |   We have carefully selected several similar problems for you:  2333 2298 1399 2446 2289 
 
 //187MS    320K    650 B    G++
/* 题意:
给你n块木板,长为ai,要用这些木板分成k块等长的木板,问最长可为多长 二分法:
和之前某题一样的想法,就是计算出当长度为x时可得到的木板块数是否符合
然后几时二分的思想做。 */
#include<stdio.h>
#include<string.h>
double a[];
int n,k;
int fac(double x)
{
int cnt=;
for(int i=;i<n;i++)
cnt+=(int)(a[i]/x);
return cnt;
}
int main(void)
{
while(scanf("%d%d",&n,&k),n+k)
{
double l=;
double r=;
for(int i=;i<n;i++){
scanf("%lf",&a[i]);
r+=a[i];
}
r/=k;
while(r-l>=0.00001){
double mid=(r+l)/;
int m=fac(mid);
if(m>=k) l=mid;
else if(m<k) r=mid;
}
//printf("%d\n",fac(r));
printf("%.2lf\n",l);
}
return ;
}

hdu 1551 Cable master (二分法)的更多相关文章

  1. HDU 1551 Cable master

    题解:很显然的二分检索,在算法艺术上看过原题,不过这里要注意精度: #include <cstdio> int n,m; ]; bool test(double x){ ,i; ;i< ...

  2. HDU 1551 Cable master【二分答案】

    题意:给出n块木板,它们分别的高度,现在要把它们裁切成k块,问裁切成的最大的高度 二分答案,上限是这n块木板里面的最大值 然后每一个答案去判断一下是否满足能够裁切成k块 #include<ios ...

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

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

  4. Cable master 求电缆的最大长度(二分法)

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...

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

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

  6. Cable master--hdu1551(二分法)

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

  7. poj1064 Cable master(二分)

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

  8. POJ 1064 Cable master (二分)

    题目链接: 传送门 Cable master Time Limit: 1000MS     Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...

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

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

随机推荐

  1. mongodb基础环境部署(windows系统下)

    Normal 0 false 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNorma ...

  2. 基于PHP的微信公众平台开发(TOKEN验证,消息回复)

    微信公众平台开发 实现步骤: 第一步:填写服务器配置 登录微信公众平台官网后,在公众平台后台管理页面 - 开发者中心页,点击“修改配置”按钮,填写服务器地址(URL).Token和EncodingAE ...

  3. 【Mysql】给mysql配置远程登录

    grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option; flush privileges ...

  4. Codeforces Round #438 C - Qualification Rounds 思维

    C. Qualification Rounds time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. 通过aop添加日志管理

    1.使用spring 的 aop 技术切到自定义注解上,所以先创建一个自定义注解类 import java.lang.annotation.*; @Target(ElementType.METHOD) ...

  6. stm32--free modbus 1.5.0移植(作为从机)

    添加文件 获取原始free modbus library(官网) 将...\freemodbus-v1.5.0\demo\BARE中的所有文件复制到...\freemodbus-v1.5.0\modb ...

  7. webstorm git提交不成功的

    git pull git pull origin master git pull origin master --allow-unrelated-histories

  8. ajax跨域请求_url:http://XXX

    利用别的项目提供的一个接口,传入用户名和密码,根据返回的结果判断登陆成功与否. 不经过后台,在js中用ajax实现.对ajax而言,发送跨域请求,与一般写法不同. 如果支持jsonp,则将dataTy ...

  9. mt_vqmon异常数据分析

    mt_vqmon异常数据分析 1.首缓冲时间值异常(1) 分析:当第一个m3u8请求时,已经记录request时间,1423716972224, 正常情况会立即请求分片列表. 上述图表明请求了一个m3 ...

  10. windows下使用RoboCopy命令进行文件夹增量备份

    RoboCopy,它是一个命令行的目录复制命令,自从Windows NT 4.0 开始就成为windows 资源工具包的一部分,然后在Windows Vista.Windows 7和 Windows ...