Cable master 求电缆的最大长度(二分法)
Description
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 is ended by line containing two 0's.
Output
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
Sample Output
#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 求电缆的最大长度(二分法)的更多相关文章
- poj1064 Cable master(二分)
Cable master 求电缆的最大长度(二分法) Description Inhabitants of the Wonderland have decided to hold a region ...
- POJ 1064 Cable master (二分法+精度控制)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65358 Accepted: 13453 De ...
- Cable master(二分-求可行解)
Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...
- hdu 1551 Cable master (二分法)
Cable master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 二分法的应用:POJ1064 Cable master
/* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
- Cable master(二分题 注意精度)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26596 Accepted: 5673 Des ...
- poj 1064 Cable master【浮点型二分查找】
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29554 Accepted: 6247 Des ...
- Cable master(好题,二分)
Cable master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
随机推荐
- redis的安装(图文详解)
我这里,搭建在 继续
- 转:从《The C Programming Language》中学到的那些编程风格和设计思想
这儿有一篇写的很好的读后感:http://www.cnblogs.com/xkfz007/articles/2566424.html 读书不是目的,关键在于思考. 很早就在水木上看到有人推荐& ...
- 浅谈Java中static作用--转
static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...
- Java异常概念
- 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 ...
- CentOS6.5下中文输入法的相关问题
问题.点击Input Method Preferences没反应. 首先执行 yum install "@Chinese Support" yum install -yibus-t ...
- 在input标签里只能输入数字
<input type='text' onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,''); ...
- 外文翻译 《How we decide》被情感愚弄 第一节
本节为第三章的起始. 书的导言 本节阅读感言:情感系统脱离控制的后果是毁灭性的. Ann Klinestiver 在一所高中做英文老师,她被诊断为患帕金森综合症.在课堂上,当她正准备和学生们谈及一些莎 ...
- spring boot jar启动
1.依赖包输出 记得禁用热加载 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactI ...
- 证明碰撞集问题(Hitting Set)是NP-complete
证明碰撞集问题(Hitting Set)是NP-complete Problem In the HITTING SET problem, we are given a family of sets { ...