A - Cable master

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.

InputThe 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.
OutputFor 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

 #include<iostream>
using namespace std; double a[];
int n,k;
int solve(double x){//用于判断按照长度x分割,能不能得到大于等于需求量k
int sum=;
for(int i=;i<n;i++)
sum += a[i]/x;
if(sum >= k) return ;
else return ;
} int main(){
double right = 0.0;
while(~scanf("%d %d", &n, &k) && n && k){
for(int i=; i<n; i++){
scanf("%lf", &a[i]);
if(a[i]>right) right = a[i];//找到长度最大量最为二分的右值
}
double mid, left=a[]/k;
while(right-left > 1e-){
mid = (right + left)/;
if(solve(mid)) left = mid;
else right = mid;
}
printf("%.2lf\n",left);
}
}

												

二分-A - Cable master的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. poj1064 Cable master(二分)

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

  9. 【POJ - 1064】Cable master(二分)

    Cable master Descriptions 输入2个数 N  K n条绳子    要分成大于等于k段 求每段最长多长呢?并且每段不能小于1cm 必须以厘米精度写入数字,小数点后正好是两位数.如 ...

随机推荐

  1. JavaScript九九乘法表

    JavaScript九九乘法表 <script> for (var i = 1; i < 10; i++) { for (var j = 1; j <= i; j++) { d ...

  2. IDEA 优化使用配置

    IDEA设置鼠标滑轮改变字体大小 点击 File - settings,找到 Editor - General,如图所示,勾上 Change font size(Zoom) with Ctrl+Mou ...

  3. 纪中某日c组模拟赛 2314. 最短路

    2314. 最短路 (File IO): input:dti.in output:dti.out 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   Goto Problem ...

  4. junit 运行(eclipse + IDEA)

    记得刚用IDEA  开发的时候, 什么都还不熟,以为junit 运行还跟eclipse 一样, 结果试了后才知道是不一样的. 现在刚好写junit 相关的,也就都记录下来吧 Eclipse:eclip ...

  5. JavaScript的语法、数据类型、基本算数和逻辑运算操作

    str.toString() 可以把字符串.数值.布尔值.对象转为字符串 String(str) 任何数值强制转换为字符串类型 <!DOCTYPE html> <html lang= ...

  6. CSS语法、选择器、继承、层叠

    行内样式(内联样式) <h1 style="color:red;font-size:20px;">css行内样式</h1> 内部样式表(嵌入样式) < ...

  7. 如何利用 WPS Office 进行 IIS Log 分析

    找到 IIS Log 打开 Internet Information Service (IIS) Manager 点击左侧 Connections > Sites,在右侧 Sites 列表中定位 ...

  8. ROS 环境变量配置

    unbantu16.04 linux 版本,  ros系统 kinetic版本 1. ros系统可以通过rospack find  package_name  /   rosrun package_n ...

  9. nginx tar包安装步骤

    1.将tar包通过 Xftb工具传输到远程服务器 2.通过 cd 命令进入存放nginx包的文件夹目录 3.tar -zxvf + 文件名 解压 4.cd nginx-1.12.0 进入源码目录 5. ...

  10. spring cloud config---Could not resolve placeholder 'xxx' in string value "${xxx}"

    初学SpringCloud 跟着视频写配置 前前后后检查了许久,配置代码没问题 最后发现是client项目的配置文件名有问题,不应该是application.yml 而是bootstrap.yml 那 ...