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条长 ...
随机推荐
- 10.24JS日记
1.函数都有返回值,人为return,返回什么就是什么,否则,他的返回值就是undefined 而方法的本质也是函数,所以也有返回值 document.getElementById()返回的是获取的标 ...
- mysql-5.7.19免安装版的配置方法
1. 下载MySQL Community Server 5.6.13 2. 解压MySQL压缩包 将以下载的MySQL压缩包解压到自定义目录下,我的解压目录是: "D:\Pr ...
- andorid 计算器
avtivity_main.xml <?xml version="1.0" encoding="utf-8"?> <GridLayout xm ...
- 前端面试问题css汇总
1,行内元素有哪些?块级元素有哪些?空元素有哪些?CSS的盒模型? 块级元素:div p h1 h2 h3 h4 form ul li 行内元素: a b br i span input select ...
- suricata 原文记录
如何在 Linux 系统上安装 Suricata 入侵检测系统 编译自:http://xmodulo.com/install-suricata-intrusion-detection-system-l ...
- 利用gulp搭建less编译环境
什么是less? 一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承, 运算, 函数. LESS 既可以在 客户端 上运行 (支持IE 6+, Webkit, ...
- ssh密钥讲解
我们用ssh连接机器时候需要输用户名.密码,但是直接写账户文件的时候由于用的是明文,就存在安全的问题了.别人一旦截取了数据就获得了隐私了.这时候就用上ssh的密钥. ssh的密钥存是成对出现的,一个叫 ...
- Python之paramiko模块
今天我们来了解一下python的paramiko模块 paramiko是python基于SSH用于远程服务器并执行相应的操作. 我们先在windows下安装paramiko 1.cmd下用pip安装p ...
- 使用hMailServer搭建邮件服务器
本文没有什么高深的技术内容,只是使用hMailServer,介绍搭建邮件服务器的全过程,供参考. 一.安装邮件服务器组件 打开软件,点下一步 选择存储数据的数据库,这里有两种选择, 一种是使用嵌入型数 ...
- merge_关系
create(olive:Person{chau:"Bill White",name:"Olive Stone",bornin:"New York&q ...