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

//给你n段电缆,然后给出一个k代表要求从n段截取的段数
//然后让你从这n段电缆中截取等长度的电缆,问最大能截取的长度是多大
#include<string>
#include<stdio.h>
#include<iomanip>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll; int n,k;
int a[10005]; int judge(int x)
{
int sum=0;
for(int i=0; i<n; i++)
sum+=a[i]/x;
if(sum>=k) return 1;
else return 0;
}
int main()
{
while(~scanf("%d%d",&n,&k))
{
for(int i=0; i<n; i++)
{
double f;
scanf("%lf",&f);
a[i]=(int)(f*100);
}
sort(a,a+n);
int high=a[n-1],low=1;
while(low<=high)
{
int mid=(low+high)>>1;
if(judge(mid)) low=mid+1;
else high=mid-1;
}
cout<<fixed<<setprecision(2)<<(double)high/100.0<<endl;//fixed 和 setpriecision 连用可以控制输出
}
return 0;
}

Cable master POJ - 1064的更多相关文章

  1. Divide and Conquer:Cable Master(POJ 1064)

    缆绳大师 题目大意,把若干线段分成K份,求最大能分多长 二分法模型,C(x)就是题干的意思,在while那里做下文章就可以了,因为这个题目没有要求长度是整数,所以我们要不断二分才行,一般50-100次 ...

  2. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  3. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  4. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  5. 二分搜索 POJ 1064 Cable master

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

  6. POJ 1064 Cable master (二分)

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

  7. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  8. POJ 1064 Cable master

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37865   Accepted: 8051 Des ...

  9. poj 1064 Cable master【浮点型二分查找】

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29554   Accepted: 6247 Des ...

随机推荐

  1. KMP next表模板

    void makeNext(const char P[],int next[]) { int q,k;//q:模版字符串下标:k:最大前后缀长度 int m = strlen(P);//模版字符串长度 ...

  2. linux系统df和du命令的区别

    发现一台用户的电脑,df检查出来的/磁盘空间占用了16G,比用du查看得到的磁盘空间大的多,du查看/下所有程序目录加起来还不到5G.这是什么原因呢? 即便是有隐藏文件,查了也很小啊.   因为df和 ...

  3. C/C++程序员必备的15个编辑器和集成开发环境

    我们有许多的编程语言,像 Java,NET,PHP,Ruby,Perl 和 Python 等,但今天我们要讨论的是两个最古老和流行的语言的C和C++.它们都有其特殊的地方,更有效的功能和支持的工具,这 ...

  4. Linux 安装tomcat,搭建web app运行环境

    Tomcat 8 下载地址:https://tomcat.apache.org/download-80.cgi 解压tomcat:tar -xf apache-tomcat-8.5.31.tar.gz ...

  5. javaScript 中的一些日常用法总结

    从今天开始把开发中常用到的js语法 一一记录下来 方便以后复习回顾用: 1:对字符串进行替换 replace 以及 replaceAll replace : var begin_date =begin ...

  6. jQuery 页面加载初始化

    jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看习惯吧,本人觉得第二种方法最好,比较简洁. 第一种: $(document).ready(functio ...

  7. react input 设置默认值

    1.text类型 <input type="text" value={默认值} />  ,这种写法可以显示默认值,但不能对输入框进行编辑 正确写法: <input ...

  8. flask插件系列之flask_restful设计API

    前言 flask框架默认的路由和视图函数映射规则是通过在视图函数上直接添加路由装饰器来实现的,这使得路由和视图函数的对应关系变得清晰,但对于统一的API开发就变得不怎么美妙了,尤其是当路由接口足够多的 ...

  9. [转载]FFmpeg完美入门[4] - FFmpeg应用实例

    1 用FFserver从文件生成流媒体 一.安装ffmpeg 在ubuntu下,运行sudo apt-get ffmpeg 安装ffmpeg,在其他linux操作系统下,见ffmpeg的编译过程(编译 ...

  10. shell脚本执行方式

    # BY THE WAY, 其实这块内容算是比较简单的,但是都比较常记得它最基本的两种方式,另外两种却忘记了 1. 利用sh或bash命令执行 sh test.sh bash test.sh 2. 在 ...