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. Chosen 基本使用

    点击下载Chosen 引入文件 chosen.css jquery-1.7.1.min.js chosen.jquery.js 绑定数据: for (var i = 0; i < data.le ...

  2. 检测 HTML5\CSS3\JAVASCRIPT 在浏览器的适应情况

    CSS3 Selectors Test : 这是CSS3.INFO网站提供的css选择器测试页面,它能够详细显示当前浏览器对所有CSS3选择器的支持情况.启动测试,浏览器会自动测验,并已列表的方式显示 ...

  3. box-shadow实例1

    实例一: 1.html <div class="paddingMiddle"> <div class="blank"></div& ...

  4. execlp函数使用

    原文:http://blog.sina.com.cn/s/blog_6a1837e901011167.html execlp(从PATH 环境变量中查找文件并执行)   相关函数:   fork,ex ...

  5. PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法

    1 PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法如下, 依次打开Tools -- Execute Commands -- Run Script,运 ...

  6. js前台获取list的demo

    后台 bannerlist=homePageService.searchBanner(bannerVO); // 注意这里的Gson的构建方式为GsonBuilder,区别于test1中的Gson g ...

  7. linux创建SVN客户端,服务器

    1- linux基本都自带svn 2-创建svn服务器 新创建服务器代码仓库 # svnadmin create serversvn 这样,我们就在~/目录下新建了版本库serverSvn. 3-修改 ...

  8. PHP 中 AJAX 中文乱码解决

    最近,在用PHP做一个AJAX功能时,出现了中文乱码.在网上搜索了一上,很多是有说不过试过都不行,我页面的的编码是UTF-8的,MYSQL中也是UTF-8的.以前在.NET中也遇到这样的问题,但只是在 ...

  9. Python模块的介绍

    Python模块的学习: 1.os模块: 下面只对os模块中几个比较常用的方法做一些简单的示例: os.system():这个方法在shell中体现的比较多,在dos命令行中也可以执行,下面就以在do ...

  10. 编译安装hph

    一.安装相关的依赖: yum -y install gcc gcc-c++ bzip2-devel libjpeg-devel libpng-devel freetype-devel libxml2- ...