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 first line of the input file contains two integer numb ers 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 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.

Output

Write to the output file 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 file must contain the single number "0.00" (without quotes).

Sample Input

4 11
8.02
7.43
4.57
5.39

Sample Output

2.00

思路:简单的二分问题,就是精度让人头大,代码如下:
#define eps 1e-9

const int maxm = ;

int n, m;
double buf[maxm]; bool check(double d) {
int num = ;
for(int i = ; i < n; ++i) {
num += (int)(buf[i] / d);
}
return num >= m;
} int main() {
scanf("%d%d", &n, &m);
double l = 0.01, r = , mid, maxsum = 0.0;
for (int i = ; i < n; ++i) {
scanf("%lf",&buf[i]);
r = max(r, buf[i]);
maxsum += buf[i];
}
if(maxsum * < m) {
printf("0.00\n");
return ;
}
while(r - l > eps) {
mid = (r + l) / 2.0;
if(check(mid))
l = mid;
else
r = mid;
}
printf("%.2lf\n", r - 0.00499);
return ;
}

 网上看到的别人的精度总结和POJ(雾

 原帖地址:https://blog.csdn.net/vmurder/article/details/44347241

												

最新文章

  1. Linux 查看进程和删除进程
  2. C# Monitoring-network
  3. php获取网页中图片并保存到本地
  4. Processon 一款基于HTML5的在线作图工具
  5. LightOj_1408 Batting Practice
  6. 自主架设VOIP系统
  7. 蓝桥杯-格子中输出-java
  8. Android&#160;stdio打开特定网页
  9. 配置HTTPS服务
  10. Amaze UI 是一个移动优先的跨屏前端框架。 http://amazeui.org/
  11. Java修改maven的默认jdk版本为1.7
  12. HTTP 403 ,tomcat配置HTTPS,无法访问 返回状态码HTTP 403
  13. react render
  14. WebRTC 学习之 WebRTC 简介
  15. [SCOI2015] 情报传递
  16. UVA11988-Broken Keyboard(数组模拟链表)
  17. JDBC(1)—Connection
  18. Java后端开发奋斗之路
  19. SpringMVC中数据转换
  20. ROS(URDF机器人建模)

热门文章

  1. Python:函数基础
  2. springboot2.x整合redis
  3. 2.4G芯片
  4. MySQL复制方法
  5. Mac 系统添加右键功能菜单--新建 office,文档等
  6. mysqld: [ERROR] Found option without preceding group in config file D:\TONG\mysql-5.7.19-winx64\my.ini at line 1!
  7. word2vec 构建中文词向量
  8. 利用正则表达式判断Java中的秒钟、分钟、小时、日、月是否符合规则
  9. sprintf 、vsprintf 、_vsntprintf
  10. 李德胜系列——李德胜和CPC人的初心