POJ1063Cable master(二分搜索)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 36288 | Accepted: 7743 |
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 <math.h>
#include <iomanip>
using namespace std;
const int MAXN=;
const double ESP=1.0e-6;
int n,k;
double cab[MAXN];
double test(double l)
{
int s=;
for(int i=;i<n;i++)
{
s+=(int)(cab[i]/l);
}
return s>=k;
}
int main()
{
while(cin>>n>>k)
{
for(int i=;i<n;i++)
{
cin>>cab[i];
}
double l=0.0;
double r=100000000.0;
while(fabs(r-l)>ESP)
{
double mid=(l+r)/;
if(test(mid)) l=mid;
else r=mid;
}
double res=floor(r*)/100.0;
cout<<showpoint<<setprecision()<<fixed<<res<<endl;
}
return ;
}
POJ1063Cable master(二分搜索)的更多相关文章
- Poj:1064 : :Cable master (假定一个解并判断是否可行)(二分搜索答案)
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- 二分搜索 POJ 1064 Cable master
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- 不光是查找值! "二分搜索"
2018-11-14 18:14:15 二分搜索法,是通过不断缩小解的可能存在范围,从而求得问题最优解的方法.在程序设计竞赛中,经常会看到二分搜索法和其他算法相结合的题目.接下来,给大家介绍几种经典的 ...
- 二分搜索 - Binary Search
二分搜索是一种在有序数组中寻找目标值的经典方法,也就是说使用前提是『有序数组』.非常简单的题中『有序』特征非常明显,但更多时候可能需要我们自己去构造『有序数组』.下面我们从最基本的二分搜索开始逐步深入 ...
- C++分治策略实现二分搜索
问题描述: 给定已排好序的n个元素组成的数组,现要利用二分搜索算法判断特定元素x是否在该有序数组中. 细节须知: (1)由于可能需要对分治策略实现二分搜索的算法效率进行评估,故使用大量的随机数对算法进 ...
- 不光是查找值!"二分搜索"
从有序数组中查找某个值 问题描述:给定长度为n的单调不下降数列a0,…,an-1和一个数k,求满足ai≥k条件的最小的i.不存在则输出n. 限制条件:1≤n≤1060≤a0≤a1≤…≤an-1< ...
- xamarin MasterDetailPage点击Master时卡顿现象
在很多项目中经常会使用到MasterDetailPage的布局方式,而且一般做为主页面来开发,在开发中,发现一个并不算Bug的问题,但是却发生了,以此记录下来,方便大家探讨. 现象是这样的,我开发了一 ...
- backup3:master 数据库的备份和还原
在SQL Server 中,master 数据库记录系统级别的元数据,例如,logon accounts, endpoints, linked servers, and system configur ...
随机推荐
- 单周期CPU设计
终于有点时间了,恰好多周期的设计也已经完成,其实只想写写多周期的,无奈单周期补上才好,哈哈哈~ —————+—————黄金分割线—————+————— 首先要理解什么叫单周期CPU(与后面多周期CPU ...
- .NET应用程序默认使用管理员身份打开
1.在源码的Properties目录中找到 app.manifest(如果没有进入第二步,有跳过第二步) 2.如果没有app.manifest文件可以打开项目属性,找到安全性项,勾上启用 ClickO ...
- 【bzoj1260】涂色paint[CQOI2007](区间dp)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1260 这道题其实和codeforces607B有点像,然而做过原题的我居然没看出来.. ...
- Android深度探索(卷1)HAL与驱动开发 虚拟环境的安装
前言: 最近在看<Android深度探索(卷1)HAL与驱动开发>安装随书带的虚拟环境浪费了很多时间,说是虚拟环境的安装倒不如说是虚拟环境的导入,其实没什么技术含量,也没有什么复杂的,只是 ...
- 【转】php 操作数组(合并,拆分,追加,查找,删除等)
1. 合并数组 array_merge()函数将数组合并到一起,返回一个联合的数组.所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加.其形式为: array array_merg ...
- java创建多线程的三种方式
/***************************继承Thread类创建多线程************************/ public class FirstThread extends ...
- HDU1565 方格取数(1)
Problem Description 给你一个n*n的格子的棋盘,每个格子里面有一个非负数.从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数 ...
- java中的向下转型
1.父类对象可以强制转换为子类对象,但是前提是此父类对象为子类对象实例化的结果. e.g. Fruit fruit=new Apple(); Apple a=(Apple)fruit;//ok e.g ...
- audiojs 音频插件使用教程
audiojs 音频插件使用教程 github地址 https://kolber.github.io/audiojs/ 依赖文件 <script src="https://cdn.bo ...
- struct2学习
struct1和webwork产生Struts2. struts2每次访问必定创建一个action,struts1只要一个action对象. Url中动态方法调用DMI 约定优于配置.miamhuai ...