POJ1064--Cable master(Binary Search)
Description
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
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
double l[]; int n,k;
int C(double d){
int num=;
for(int i=;i<n;i++){
num+=(int)(l[i]/d);
}
return num>=k;
} int main(){
cin>>n>>k;
double m=-;
for(int i=;i<n;i++){
cin>>l[i];
m=max(m,l[i]);
}
double lb=,ub=m+0.01;
for(int i=;i<;i++){
double mid=(lb+ub)/;
if(C(mid))
lb=mid;
else
ub=mid;
}
printf("%.2f\n",floor(ub*)/);
return ;
}
POJ1064--Cable master(Binary Search)的更多相关文章
- 二分法的应用: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 ...
- poj1064 Cable master(二分查找,精度)
https://vjudge.net/problem/POJ-1064 二分就相当于不停地折半试. C++AC,G++WA不知为何,有人说C函数ans那里爆int了,改了之后也没什么用. #inclu ...
- POJ1064 Cable master 【二分找最大值】
题目:题目太长了! https://vjudge.net/problem/POJ-1064 题意分析:给了你N根长度为小数形式的棍子,再给出了你需要分的棍子的数量K,但要求你这K根棍子的长度必须是一样 ...
- POJ1064 Cable master(二分 浮点误差)
题目链接:传送门 题目大意: 给出n根长度为1-1e5的电线,想要从中切割出k段等长的部分(不可拼接),问这个k段等长的电线最长可以是多长(保留两位小数向下取整). 思路: 很裸的题意,二分答案即可. ...
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- Leetcode: Convert sorted list to binary search tree (No. 109)
Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
随机推荐
- python 数据类型 之 字典
python 3.6.5字典的特性和定义定义:{'key_1':vlaue_1,'key_2':value_2}1.键与值用冒号 : 分开2.项与项 用 , 分开 特性1.可以存放多个值,可以不唯一, ...
- (转)easyui datagrid 部分参数说明
easyui datagrid 部分参数 数据表格属性(DataGrid Properties) 属性继承控制面板,以下是数据表格独有的属性. 名称 类型 描述 默认值 columns array 数 ...
- HapMap
HapMap五周年回顾 2011-01-12 | 作者: [关闭] 作者简介:曾长青,中国科学院北京基因组所研究员,博士生导师.CUSBEA奖学金.百人计划.杰出青年基金.首批新世纪百千万人才工程国家 ...
- 基因组表达分析:如何选择RNA-seq vs. 芯片
基因组表达分析:如何选择RNA-seq vs. 芯片 发布日期:2017-03-29 10:00 DNA 芯片(上图左侧)由附着在表面的核酸探针组成.首先,从样品中提取 RNA 并转化为互补 DNA( ...
- 洛谷1462(重题1951) 通往奥格瑞玛的道路(收费站_NOI导刊2009提高(2))
1462原题链接 1951原题链接 显然答案有单调性,所以可以二分答案,用\(SPFA\)或\(dijkstra\)跑最短路来判断是否可行即可. 注意起点也要收费,\(1462\)数据较水,我一开始没 ...
- BZOJ1801或洛谷2051 [AHOI2009]中国象棋
BZOJ原题链接 洛谷原题链接 这题挺难想状态的,刚看题感觉是状压,但数据\(100\)显然不可能. 注意到每行每列只能放\(0\sim 2\)个棋子,所以我们可以将这个写入状态. 设\(f[i][j ...
- Spring ConversionService 类型转换(一)Converter
Spring ConversionService 类型转换(一)Converter Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.h ...
- 摹客 iDoc 12月上半月新功能点评
转眼就到了2018年的最后一个月,小伙伴们是不是都在奋力拼搏做年底的冲刺呢?摹客也没有放慢脚步,不断地优化,给大家带来一个又一个的惊喜.那么,让小摹来带大家看看12月摹客iDoc更新了哪些特色功能: ...
- h5页面适配iPhone X的方法
一.原生适配iphoneX 原生适配很简单,查看机型图: 只要用 #define KIsiPhoneX ([UIScreen mainScreen].bounds.size.height>8 ...
- java基本知识归集
类中可以有几种东西:属性,方法,构造器,初始化块 new创建对象时, 1.类属性和类初始化块分配空间. 2.执行默认初始化 如有父类,先为父类执行父类自己的1和2步骤,再执行上面的1和2. 一个类执行 ...