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 ...
随机推荐
- opencv python:ROI 与 泛洪填充
提取ROI区域,处理然后放回去: 泛洪填充 测试代码:显示一张图像,鼠标点击之后,会从该点开始进行填充,显示填充后的结果图像 注:二值图像的填充需要使用选项:cv2.FLOODFILL_MASK_ON ...
- Newtonsoft.Json小记
/*json相关*/ //http://www.cnblogs.com/hongfei/p/3593936.html string jsonObject = "{\"phone\& ...
- Codeforces Round #621 (Div. 1 + Div. 2) C. Cow and Message
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is ...
- (转)__attribute__之section 分析详解
原文地址:__attribute__之section详解 前言 第一次接触 "section" 是在公司的一个STM32的项目代码中,前工程师将所有的初始化函数都使用的" ...
- linux下postgres创建hive数据库
操作步骤 #登录 [root@xxx01 ~]# su postgres bash-4.2$ psql -U postgres could not change directory to " ...
- 【PAT甲级】1043 Is It a Binary Search Tree (25 分)(判断是否为BST的先序遍历并输出后序遍历)
题意: 输入一个正整数N(<=1000),接下来输入N个点的序号.如果刚才输入的序列是一颗二叉搜索树或它的镜像(中心翻转180°)的先序遍历,那么输出YES并输出它的后序遍历,否则输出NO. t ...
- HashMap 原理?jdk1.7 与 1.8区别
HashMap 结构 以及 1.7 与 1.8 一.区别 01. jdk 1.7 用的是头插法,而jdk1.8以后使用的是尾插法?为什么这样做呢?因为 JDK 1.7 是用单链表进行纵向延伸,采用头插 ...
- java并发初探ConcurrentSkipListMap
java并发初探ConcurrentSkipListMap ConcurrentSkipListMap以调表这种数据结构以空间换时间获得效率,通过volatile和CAS操作保证线程安全,而且它保证了 ...
- Linu计划任务/crontab命令
周期性任务计划 相关程序包: cronie:主程序包,提供了crond守护进程及相关辅助工具 cronie-anacron:cronie的补充程序:用于监控cronie任务执行状况:如cronie中的 ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)B(SET)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[2007];set<int& ...