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 ...
随机推荐
- 分布式集群环境下,如何实现session共享三(环境搭建)
这是分布式集群环境下,如何实现session共享系列的第三篇.在上一篇:分布式集群环境下,如何实现session共享二(项目开发)中,准备好了一个通过原生态的servlet操作session的案例.本 ...
- 【Nginx】解决Post请求变Get的问题
默认情况下Nginx会把post请求做一次重定向操作,然后后端收到的就成了Get请求,还会导致一些参数的遗漏. 日志如下: 172.16.1.108 - - [11/Jan/2019:18:27:09 ...
- Python+selenium定位不到元素的问题及解决方案
在操作过程中主要遇到两种阻塞的问题,总结如下: 1.页面中有iframe,定位元素时,需要用switch_to.frame()转换到元素所在的frame上再去定位 2.遇到一种新情况,有些按钮在htm ...
- azkaban web ui界面出现异常诡异“丑”界面的问题解决(图文详解)
前期博客 启动azkaban时出现User xml file conf/azkaban-users.xml doesn't exist问题解决(图文详解) 问题详情 [hadoop@master co ...
- vs直接IP访问运行项目
找到IIS Express 正在运行的项目应用程序,点击网站,会出现配置路径,找到配置路径,显示隐藏的文件夹 localhost替换成本地IP,重新运行项目,然后就可以直接通过IP访问项目,好处就是便 ...
- XSS漏洞解析(三)
系统存在xss漏洞就容易引发CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为: ...
- 基于坐标的自动化测试神器---Total Control快速入门
1.Total Control简单介绍 一款能够在PC上控制手机的软件,同时可以使用PC 触摸屏.鼠标.键盘, 全面操控 Android 手机,只需通过 USB 或 WiFi 连接手机至电脑,即可随时 ...
- 通用mapper的generator
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-genera ...
- BST AVL RBT B- B+ 的一些理解
BST(二叉查找树,排序二叉树),如果数据有序的话,组成的二叉树会形成单列的形式,导致查询效率低AVL(平衡二叉树) 使树的左右高度差的绝对值不超过2,保证了查询效率.但是插入和删除会带来多次旋转,导 ...
- Pygame - Python游戏编程入门
>>> import pygame>>> print(pygame.ver)1.9.2a0 如果没有报错,应该是安装好了~ 如果报错找不到模块,很可能是安装版本的问 ...