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. CCNA 课程 六

    路由协议概述: 通过一种路由协议学习到了多个去往同一目标网络的路由,metric小的放入路由表中.metric一样,同时放进路由表. 通过多种路由协议学习到了去往同一目标网络的路由,路由协议管理距离小 ...

  2. Nginx location指令匹配顺序规则

    location匹配命令 1. “= ”,字面精确匹配, 如果匹配,则跳出匹配过程.(不再进行正则匹配) 2. “^~ ”,最大前缀匹配,如果匹配,则跳出匹配过程.(不再进行正则匹配) 3. 不带任何 ...

  3. 如何检查BioPerl是否正确安装

    如果是Linux系统,随意打开一个终端:如果用的是Windows系统,那么打开命令提示符. 输入以下命令: perldoc Bio::SeqIO 以上命令的作用是查看Bio::SeqIO模块的文档是否 ...

  4. codeforces675D Tree Construction

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  5. hdoj1012--u Calculate e

    Problem Description A simple mathematical formula for e is where n is allowed to go to infinity. Thi ...

  6. Python显示百分比

    print(format(a/b,'.2%')) 显示两位小数的百分比显示

  7. JNI_Z

    1. ZC: 用到 VC6 ... http://blog.csdn.net/jiangwei0910410003/article/details/17465085 http://blog.csdn. ...

  8. iOS学习笔记之正则表达式

    前言 基本上每个 App 都有登录注册功能,在登录注册时需要验证用户所输入的内容是否符合规定:有时要在字符串中查找并截取符合要求的字符串,这时就需要用到正则表达式.正则表达式看起来晦涩难懂,没有什么规 ...

  9. python中常用的文件和目录操作(二)

    一. os模块概述 python os模块提供了非常丰富的方法用来处理文件和目录 二. 导入os模块: import os 三. 常用方法 1. os.name 输出字符串表示正在使用的平台,如果是w ...

  10. 算法练习3---水仙花数java版

    所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身. java程序代码如下: public class ArithTest { public static void ...