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

												

Day3-M-Cable master POJ1064的更多相关文章

  1. Cable master poj1064(二分)

    http://poj.org/problem?id=1064 题意:共有n段绳子,要求总共被分为k段.问在符合题意的前提下,每段长最大是多少? #include <iostream> #i ...

  2. 二分法的应用:POJ1064 Cable master

    /* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...

  3. poj1064 Cable master

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...

  4. poj1064 Cable master(二分)

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

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

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

  6. POJ 1064 Cable master (二分)

    题目链接: 传送门 Cable master Time Limit: 1000MS     Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...

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

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

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

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

  9. POJ 1064 Cable master

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37865   Accepted: 8051 Des ...

  10. Cable master

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...

随机推荐

  1. 27 JavaScript的引入&注释&弹窗&变量常量&数据类型及转换&内存&垃圾回收

    JS的引入: 1 内部引入 绑定元素事件如onclick="" 绑定锚点如href="JavaScript:void(0)" script标签引入,注意:如果标 ...

  2. Euler Sums系列(四)

    \[\Large\displaystyle \sum_{n=1}^\infty (-1)^n \frac{H_n}{2n+1}=\mathbf{G}-\frac{\pi}{2}\ln(2)\] \(\ ...

  3. Nexus升级、license安装和恢复密码

    原文链接:https://blog.csdn.net/ligang636/article/details/42386639 一.Nexus系列物理硬件1.1 Nexus 7010 1.2 Nexus ...

  4. 夯实Java基础(二十五)——JDBC使用详解

    1.JDBC介绍 JDBC的全称是Java Data Base Connectivity(Java数据库连接).是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问(例如MyS ...

  5. C语言-错误处理

    标记程序的运行状态和控制主要有以下几种:break/continue/return/参数的返回值/exit(int n)_exit() atexit((*p)(参数列表)): 1 break:用在开关 ...

  6. Qt实现通用模板单例

    #include <QAtomicPointer> #include <QMutex> #include <memory> using namespace std; ...

  7. [].slice.call(k).filter(function(l) { return l != 0 });

    [].slice.call(k).filter(function(l) { return l != 0 }); 将类数组调用数组方法.

  8. python浅谈编程规范和软件开发目录规范的重要性

    前言 我们这些初学者,目前要做的就是遵守代码规范,这是最基本的,而且每个团队的规范可能还不一样,以后工作了,尽可能和团队保持一致,目前初学者就按照官方的要求即可 新人进入一个企业,不会接触到核心的架构 ...

  9. zip 多维

    ll=zip([[1,3],[2,4]],[[88,99],[66,55]])a=zip(*ll)# print(list(a)) #[([1, 3], [2, 4]), ([88, 99], [66 ...

  10. 关于PGSQL连接问题

    今天把运维管理服务移植在Linux下测试,但又不想在Linux中安装PGSQL的服务器,就想让运维管理服务在虚拟机中连接windows的PG服务,却发现PG服务器一直拒绝连接,检查了网络端口之后都没问 ...