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条长 ...
随机推荐
- Java并发集合(三)-ConcurrentHashMap分析和使用
1 http://ifeve.com/hashmap-concurrenthashmap-%E7%9B%B8%E4%BF%A1%E7%9C%8B%E5%AE%8C%E8%BF%99%E7%AF%87% ...
- python: "TypeError: 'type' object is not subscriptable"
目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a di ...
- autohotkey快捷键
;已经基本修复了输入带shift的时候跟输入法中英文切换之间的冲突 SetStoreCapslockMode, off SetKeyDelay, ^CapsLock:: #UseHook ;用这个和下 ...
- windows下忘记mysql的root密码
1.停止mysql 2.命令行启动mysqlmysqld --defaults-file="c:\mysql\mysql server 5.1\my.ini" --console ...
- object SparkStreaming_StateFul {
窗口查询 ) )).reduceByKeyAndWindow(_+_,_-_,Seconds(10),Seconds(15)) 每隔15s进行查询,查询为前10s的结果.这里的值必须为采集时间 ...
- Redis的基操
redis:通常BOLEAN操作类型,操作成功返回1,操作失败返回0 通常如果往设置的key插入值,但是这个key不存在,redis则会创建 向redis里的某个key插入多个值时,值和值之间用空格隔 ...
- 【WebService】WebService之CXF的拦截器(五)
CXF拦截器介绍 CXF拦截器是功能的主要实现单元,也是主要的扩展点,可以在不对核心模块进行修改的情况下,动态添加功能.当服务被调用时,会经过多个拦截器链(Interceptor Chain)处理,拦 ...
- MySQL把本地数据库上传到linux
今天是要导入数据库到linux系统 先用Navicat把sql导出,然后登陆到linux去执行 登陆mysql: mysql -uroot -p123456 创建数据库:create database ...
- 开发简单的JavaWeb项目
一.配置相关环境 下载配置JDK,eclipse,Tomcat服务器,Mysql数据库,Navicat for MySQL(数据库可视化工具) 如果你已经做好各个环境的配置,eclipse与Tomca ...
- 用rpm命令安装定时器crontab
crontab -l command not found 准备以下安装包: ls -l总用量 1004-rw-r--r-- 1 root root 76296 10月 9 16:01 croni ...