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. chisel(安装)

    github地址 先安装homeBrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/m ...

  2. Delphi7程序调用C#写的DLL解决办法(转)

    近来,因工作需要,必须解决Delphi7写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行:    编写C#dll的方法都一样,首先在vs2005中创建一个 ...

  3. 批量更新python库

    import pip from subprocess import call for dist in pip.get_installed_distributions(): try: call(&quo ...

  4. scapy--初识

    常用的包结构: (1)OSI 5层模型 OSI中的层 功能 TCP/IP协议族 应用层 文件传输,电子邮件,文件服务,虚拟终端 TFTP,HTTP,SNMP,FTP,SMTP,DNS,Telnet 传 ...

  5. php mysql find_in_set函数 检索单子段 逗号分隔序列

    FIND_IN_SET($kwd,field) 例如在 表 AA中 numbers 字段  保存列数据 1,4,8,75,41,7 就可以使用  FIND_IN_SET(8,numbers)  查询记 ...

  6. 关于IT术语---ip、uv、pv、tps、qps、rps

    涉及到IT方面的几条术语,这里要好好说道说道: 只要和网站打交道,难免会经常听到一系列的转有名词  >>>  系统今日UV多少.PV多少.QPS多少之类的问题.这里就对这些常见的术语 ...

  7. Git的使用--将本地项目上传到Github

    Git的使用--将本地项目上传到Github 感谢作者 --> 原文链接 很早之前就注册了Github,但对其使用一直懵懵懂懂,很不熟练.直到昨天做完百度前端技术学院的task,想把代码托管到G ...

  8. django中间件CsrfViewMiddleware源码分析,探究csrf实现

    Django Documentation csrf保护基于以下: 1. 一个CSRF cookie 基于一个随机生成的值,其他网站无法得到.此cookie由CsrfViewMiddleware产生.它 ...

  9. Trident整合MongoDB

    MongoDB是大数据技术中常用的NoSql型数据库,它提供的大量的查询.聚合等操作函数,对于大量查询的日志系统来说,该MongoDB是大数据日志存储的福音.Storm的高级编程技术Trident,也 ...

  10. TCP重组问题

    今天问题: vqmon 测试一pcap抓包文件18.pcap.发现实际输出的视频分片信息和抓包不符合. ===>pts : 00:00:33 Too much data in TCP recei ...