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条长 ...
随机推荐
- istio分布式调用链Jaeger
1.安装 kubectl apply -n istio-system -f https://raw.githubusercontent.com/jaegertracing/jaeger-kuberne ...
- IIS7中的站点、应用程序和虚拟目录详细介绍
IIS7中的站点.应用程序和虚拟目录详细介绍 这里说的不是如何解决路径重写或者如何配置的问题,而是阐述一下站点(site),应用程序(application)和虚拟目录 (virtual direct ...
- PAT 1004 成绩排名 (20)(代码)
1004 成绩排名 (20)(20 分) 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为\ 第1行:正整数n 第2行:第1 ...
- Java与go哪个更适合后端开发呢?哪个更适合新手呢?
Java语言目前在后端开发领域有广泛的应用,尤其是大型互联网平台往往选择Java作为主要的后端编程语言.同时,Java自身的生态比较健全,也有大量的成功案例,所以采用Java做后端编程语言是一个风险比 ...
- Qt5+VS2010的安装及使用
在我的博客<Win7下Qt5的安装及使用>中讲解了win7下Qt5+MinGW的安装及使用,本节再讲解win7下Qt5+VS2010的安装及使用.利用Qt5+MinGW开发应用程序比较麻烦 ...
- 拍照一分钟,修图两小时,PS大神是这样修片的!
乌克兰有一个叫Viktoria Solidarnyh的美图艺术家,这个艺术家有一个特别的技能——P图,她P的图,水平真的非常赞...来感受一下.... 瞬间变成魔幻田园风... 编辑:千锋UI设计 ...
- UI设计初学者必看,这款设计神器教你快速入门
网络时代,网页和手机App已经深入到人们生活的方方面面.这也使得App界面设计越来越受青年求职者们的青睐,并纷纷投入这个行业.但是,作为UI设计初学者,究竟如何才能快速的入门?当今市场上,是否有那么一 ...
- Sliding Window Median LT480
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- fastcgi 环境变量例子
例如请求的url http://172.28.250.184:8099/aa.php?var=ccccc&value=bbbbbb 前两个字节分别代表 变量名长度 和 变量值长度. 0x0 ...
- SecureCRT乱码解决
本文不涉及编码,只说明ssh问题产生的乱码 如果终端中输出以下字符,就会出现乱码 echo -e '\xe' 还有 ctrl+v,ctrl+n也能产生乱码 恢复方法 echo -e '\xf'