Cable master

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

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
 题解:就是N根旧电缆,要求裁剪K分的最大长度;
hd过了的代码:但poj不过;;
 #include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);//temp代表能裁剪成的数量。。。
if(temp>=K)l=mid;
else r=mid;
}
return mid;
}
int main(){
while(scanf("%d%lf",&N,&K),N||K){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
printf("%.2lf\n",search());
}
return ;
}

poj ac:

 #include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);
if(temp>=K)l=mid;
else r=mid;
}
return r;
}
int main(){double d;double t;
while(~scanf("%d%lf",&N,&K)){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
d=search();
/// t=100*d;printf("%d\n",t);
printf("%.2f\n",(int)(d*)/100.0);
}
return ;
}

Cable master(好题,二分)的更多相关文章

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

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

  2. Cable master poj1064(二分)

    http://poj.org/problem?id=1064 题意:共有n段绳子,要求总共被分为k段.问在符合题意的前提下,每段长最大是多少? #include <iostream> #i ...

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

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

  4. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

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

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

  6. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  7. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  8. POJ 1064 Cable master (二分查找)

    题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...

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

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

随机推荐

  1. VirtualBox 扩展包卸载或安装失败(VERR_ALREADY_EXISTS)

    最近在卸载VirtualBox出现了无法卸载的错误.提示为Failed to install the extension. The installer failed with exit code 1: ...

  2. 使用WebRTC实现电脑与手机通过浏览器进行视频通话

    最近一直在研究WebRTC,做了一个小项目:www.meet58.com,这个项目利用WebRTC.WebSocket可以让各种设备只通过浏览器进行视频聊天,无论是电脑.手机或者是平板.下面就是手机和 ...

  3. Linux 终端訪问 FTP 及 上传下载 文件

    今天同事问我一个问题,在Linux 下訪问FTP,并将文件上传上去. 我之前一直是用WinSCP工具的. 先将文件从linux copy到windows下,然后在传到ftp上. google 一下. ...

  4. Git 上传本地命令

    1.首先建立一个文件夹用以测试 2.在test中写入一个main.c的文件 其内容如下: 3.然后就建立一个git仓库了 4.然后就是把内容加进去了,上传上去 5.然后我们看下git log的信息 6 ...

  5. js转换ascii编码如中文友转换为编码友;可防止乱码

  6. 使用maven编译的时候提示 maven-source 1.3 中不支持注释请使用 -source 5 或更高版本以启用注释的错误。

    在编译的模块的pom文件中加上 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins ...

  7. ARM9嵌入式学习笔记(1)-Linux命令

    ARM9嵌入式学习笔记(1)-Linux命令 实验1-1-2 Linux常见命令使用 添加用户useradd smb; 设置账户密码passwd smb; 切换用户su - root 关机命令shut ...

  8. UML学习-状态图

    1.状态图概述 状态图(Statechart Diagram)主要用于描述一个对象在其生存期间的动态行为,表现为一个对象所经历的状态序列,引起状态转移的事件(Event),以及因状态转移而伴随的动作( ...

  9. PHP学习笔记二十一【全局变量】

    <?PHP //定义全局变量 global $a; $a=9; //给全局变量赋值 function test1() { global $a; $a=45; } test1(); echo $a ...

  10. C# List<T>的详细用法

    所属命名空间:System.Collections.Generic List<T>类是 ArrayList 类的泛型等效类.该类使用大小可按需动态增加的数组实现 IList<T> ...