Cable master
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 36288   Accepted: 7743

Description

Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it. 
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

The first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.

Output

Write to the output file the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point. 
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(二分搜索)的更多相关文章

  1. Poj:1064 : :Cable master (假定一个解并判断是否可行)(二分搜索答案)

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...

  2. 二分搜索 POJ 1064 Cable master

    题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...

  3. POJ 1064 Cable master (二分)

    题目链接: 传送门 Cable master Time Limit: 1000MS     Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...

  4. 不光是查找值! "二分搜索"

    2018-11-14 18:14:15 二分搜索法,是通过不断缩小解的可能存在范围,从而求得问题最优解的方法.在程序设计竞赛中,经常会看到二分搜索法和其他算法相结合的题目.接下来,给大家介绍几种经典的 ...

  5. 二分搜索 - Binary Search

    二分搜索是一种在有序数组中寻找目标值的经典方法,也就是说使用前提是『有序数组』.非常简单的题中『有序』特征非常明显,但更多时候可能需要我们自己去构造『有序数组』.下面我们从最基本的二分搜索开始逐步深入 ...

  6. C++分治策略实现二分搜索

    问题描述: 给定已排好序的n个元素组成的数组,现要利用二分搜索算法判断特定元素x是否在该有序数组中. 细节须知: (1)由于可能需要对分治策略实现二分搜索的算法效率进行评估,故使用大量的随机数对算法进 ...

  7. 不光是查找值!"二分搜索"

    从有序数组中查找某个值 问题描述:给定长度为n的单调不下降数列a0,…,an-1和一个数k,求满足ai≥k条件的最小的i.不存在则输出n. 限制条件:1≤n≤1060≤a0≤a1≤…≤an-1< ...

  8. xamarin MasterDetailPage点击Master时卡顿现象

    在很多项目中经常会使用到MasterDetailPage的布局方式,而且一般做为主页面来开发,在开发中,发现一个并不算Bug的问题,但是却发生了,以此记录下来,方便大家探讨. 现象是这样的,我开发了一 ...

  9. backup3:master 数据库的备份和还原

    在SQL Server 中,master 数据库记录系统级别的元数据,例如,logon accounts, endpoints, linked servers, and system configur ...

随机推荐

  1. package.json字段简要解析

    name 必填 应用名称 version 必填 应用版本 description 选填 应用描述,多用于搜索,在npm search 时可以用到 keywords 选填 应用关键字,也多用于搜索 sc ...

  2. 算法总结之 构造数组MaxTree

    一个数组的MaxTree定义如下: 数组必须没有重复元素 MaxTree是一颗二叉树,数组的每一个值对应一个二叉树的节点 包括MaxTre树在内且在其中的每一颗子树上,值最大的节点都是树的头 给定一个 ...

  3. 发现程序bug思路

    大家有没有遇到过项目,程序出现个bug,但花了好久(真的是a long long time啊)才发现引发这个问题的原因,心想原来就这个原因导致的啊,要是早想到就好了! 其实我们确实的是方法,希望我的抛 ...

  4. 查找文件【TLCL】

    locate locate 执行快速的路径名数据库搜索,输出每个与指定子字符串相匹配的路径名. locate bin/zip locate 命令的数据库是updatedb命令创建的. find loc ...

  5. [kuangbin带你飞]专题十 匹配问题 一般图匹配

    过去做的都是二分图匹配 即 同一个集合里的点 互相不联通 但是如果延伸到一般图上去 求一个一般图的最大匹配 就要用带花树来解决 带花树模板 用来处理一个无向图上的最大匹配 看了一会还是不懂  抄了一遍 ...

  6. 在虚拟机里安装ubuntu

    1.下载ubuntu镜像文件 https://mirrors.aliyun.com/ubuntu-releases/17.04/ubuntu-17.04-desktop-amd64.iso 2.创建虚 ...

  7. Spring MVC数据绑定大全 .

    刚开始用spring mvc 做web开发时,经常会不知道如何合适绑定页面数据.用惯struts2的朋友更认为spring mvc 绑定数据不如struts2方便(本人最开始也是这么认为),经过一段时 ...

  8. Nhibernate Fluent INNER JOIN 查询

    var list = session.QueryOver<PluginEntity>().JoinQueryOver(o => o.PluginModule, NHibernate. ...

  9. Python学习之路day3-字符编码与转码

    一.基础概念 字符与字节 字符是相对于人类而言的可识别的符号标识,是一种人类语言,如中文.英文.拉丁文甚至甲骨文.梵语等等.    字节是计算机内部识别可用的符号标识(0和1组成的二进制串,机器语言) ...

  10. linux 部署nginx----端口转发

    一.解压安装 tar zxvf nginx-.tar.gz cd nginx- ./configure --with-http_stub_status_module --with-http_ssl_m ...