Day3-M-Cable master POJ1064
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
Output
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的更多相关文章
- Cable master poj1064(二分)
http://poj.org/problem?id=1064 题意:共有n段绳子,要求总共被分为k段.问在符合题意的前提下,每段长最大是多少? #include <iostream> #i ...
- 二分法的应用:POJ1064 Cable master
/* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...
- poj1064 Cable master
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- poj1064 Cable master(二分)
Cable master 求电缆的最大长度(二分法) Description Inhabitants of the Wonderland have decided to hold a region ...
- 【POJ - 1064】Cable master(二分)
Cable master Descriptions 输入2个数 N K n条绳子 要分成大于等于k段 求每段最长多长呢?并且每段不能小于1cm 必须以厘米精度写入数字,小数点后正好是两位数.如 ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- [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: 37865 Accepted: 8051 Des ...
- Cable master
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
随机推荐
- ElementUI el-table 表格 行选择框改为单选
实现方法 首先,表格加一列 <el-table-column type="selection" width="55"></el-table-c ...
- JS bind()方法、JS原生实现bind()
一.arguments的含义 // arguments 是一个对应于传递给函数的参数的类数组对象 function a(){ console.log(arguments); } a(); // Arg ...
- Mac夜神模拟器99%无法正常使用
PS:部分因更新OS X导致的卡99%可以尝试更新VBOX来解决此问题. 下载VBOX地址:https://www.virtualbox.org/wiki/Downloads 选择对应 ...
- C语言-排序和查找
一 冒泡排序:算法特点:两层循环外层控制排序的趟数,内存控制相邻元素两两比较的次数.n个数共需n-1趟,(i=1;i<n;i++)趟数=n-1-1+1,其中第j趟需要相邻元素两两比较的次数为n- ...
- 如何解决Serv-U管理密码忘记
如何解决Serv-U管理密码忘记 2016-06-17 15:46:48 2581次 解决方法: 点击“FTP服务器”,停止FTP服务器.进入Serv-U安装目录,默认C:Program FilesS ...
- php海量架构
架构 Varnish+nginx+php(FastCGI)+MYSQL5+MenCache+MenCachedb 说明:我在设计系统架构时,进行了大胆的尝试,只用6台Web服务器,达到了可承受4000 ...
- base64,base32bit加密解密
import base64 str='admin' str=str.encode('utf-8') #加密 bs64=base64.b64encode(str) #解密 debs64=base64.b ...
- IDEA 解决 Maven 依赖冲突的高能神器,这一篇够不够?
1.何为依赖冲突 Maven是个很好用的依赖管理工具,但是再好的东西也不是完美的.Maven的依赖机制会导致Jar包的冲突.举个例子,现在你的项目中,使用了两个Jar包,分别是A和B.现在A需要依 ...
- BlockingQueue的几个实现分析
ArrayBlockingQueue 底层以数组的结构存放队列元素,容量大小不可改变. 先看下变量: items:数组,用于存放队列中的元素 takeIndex:获取元素的索引位置 putIndex: ...
- Hosts工作原理及作用
Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开.其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”.当用户在浏览器中输入一个需要登录的网址时,系统会先检查系自己的Ho ...