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 ...
随机推荐
- 【代码审计】VAuditDemo 重装漏洞
一.源码安装漏洞介绍 一般在PHP源码程序都有一个初始安装的功能,如果相关代码没有对参数进行严格过滤,可能会导致攻击者访问安装页面(install.php)或构造数据包,对网站进行重新安装,从而危害网 ...
- N3K license安装
1.获取设备SN和PAK SN获取: Switch#show license host-id 注意:IOS设备中为:show license udi PAK获取: PAK是单独购买license后,c ...
- 【剑指Offer面试编程题】题目1509:树中两个结点的最低公共祖先--九度OJ
题目描述: 给定一棵树,同时给出树中的两个结点,求它们的最低公共祖先. 输入: 输入可能包含多个测试样例. 对于每个测试案例,输入的第一行为一个数n(0<n<1000),代表测试样例的个数 ...
- float元素上-margin的用法
css标准,float元素上的负margin表示把下面的元素向对应方向移动,并且覆盖上一个元素(这里是指html中元素的声明顺序). 标准情况下我们用float 时候是这样的. -margin通俗点说 ...
- LNMP架构及应用部署!(重点)
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构. WNMP代表的就是:Windows系统下Nginx+MySQL+PHP这种网站服务器架构. WAMP代表的就是: ...
- Cake ZOJ - 3537
题目链接 本题也是区间dp三角剖分板子题,只不过加入了判断是否是凸包,计算顺序要用凸包顺序(凸包板) #include<bits/stdc++.h> using namespace std ...
- ajax相同url和参数,将不会重复发起请求
IE浏览器下使用GET发送请求时,如果两次请求的地址和参数相同,在不刷新页面的情况下,浏览器会缓存第一次请求的内容,服务端更新后浏览器仍然显示第一次的内容. 解决办法: 一. GET请求URL后加随机 ...
- springBoot整合mybatis-plus关闭自动转换小驼峰命名规则
增加配置信息 mybatis-plus: configuration: map-underscore-to-camel-case: false
- 19年读100本书之第二本--《OKR工作法》-克里斯蒂娜 沃特克
0,一句话概括书的内容? OKR(objective key result),即目标与关键结果. 1,我从这本书能得到什么? 2,核心内容是什么? 3,我要怎么做?
- linux下后台执行shell脚本nohup
(一)使用nohup后台执行脚本 脚本执行结果记录到nohup.out文件中 (二)使用&后台执行脚本 使用&符号在后台执行命令或脚本后,如果你退出登录,这个命令就会被自动终止掉