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.0

题意:有n段长度分别为Li的电缆,要求把它们分割成K条长度为X的电缆,问X的最大值为多少。

 #include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
#define PI acos(-1.0)
using namespace std;
#define Inf 0x3f3f3f3f
#define exp 1e-8
typedef long long ll;
int m,n;
double str[];
int visit[][][][];
int dis[][];
int di[][]= {{,,,},{,,,-},{,,,},{,,-,},{,,,},{,-,,},{,,,},{-,,,}};
map<ll,ll>::iterator it;
bool solve(double mid)
{
int ans=;
for(int i=;i<m;i++)
{
ans+=(int)(str[i]/mid);
}
return ans>=n;
}
int main()
{
int i,j;
while( scanf("%d%d",&m,&n)!=-){
for(i=;i<m;i++)
{
scanf("%lf",&str[i]);
}
double left=,right=Inf,mid;
int ans;
i=;
while(i--)
{
mid=(left+right)/;
if(solve(mid))
{
left=mid;
}
else
{
right=mid;
}
}
printf("%0.2lf\n",floor(right*)/100.0);
}
return ;
}

题解:将X视为变量,可知它的范围为0~max;  那么问题就变成了电缆长度取X时,所得的电缆条数大于,还是等于,或小于K的问题。  用二分查找法能很快的找出K的值,不过要注意精度,直接输出时会四舍五入,五入时的结果肯定是错的,注意向下取整。

Cable master(二分-求可行解)的更多相关文章

  1. poj1064 Cable master(二分)

    Cable master 求电缆的最大长度(二分法)   Description Inhabitants of the Wonderland have decided to hold a region ...

  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 (二分)

    题意:给定 n 条绳子,它们的长度分别为 ai,现在要从这些绳子中切出 m 条长度相同的绳子,求最长是多少. 析:其中就是一个二分的水题,但是有一个坑,那么就是最后输出不能四舍五入,只能向下取整. 代 ...

  4. POJ 1064 Cable master (二分答案)

    题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...

  5. [POJ] 1064 Cable master (二分查找)

    题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可 ...

  6. POJ 1064 Cable master | 二分+精度

    题目: 给n个长度为l[i](浮点数)的绳子,要分成k份相同长度的 问最多多长 题解: 二分长度,控制循环次数来控制精度,输出也要控制精度<wa了好多次> #include<cstd ...

  7. poj 1064 Cable master 二分 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1064 题解 二分即可 其实 对于输入与精度计算不是很在行 老是被卡精度 后来学习了一个函数 floor 向负无穷取整 才能ac 代码如下 ...

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

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

  9. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

随机推荐

  1. hibernate映射(一对一、一对多、多对一、多对多)配置 【转】

    多对一关联映射:在多的一端加入一个外键指向一的一端,它维护的关系是多指向一 一对多关联映射:在多的一端加入一个外键指向一的一端,它维护的关系是一指向多 也就是说一对多和多对一的映射策略是一样的,只是站 ...

  2. 专业工具软件AutoCAD复习资料

    专业工具软件AutoCAD复习资料 下载地址:http://download.csdn.net/detail/zhangrelay/9849503 这里给出了一些dwg格式的CAD资料,用于课后学习和 ...

  3. 【Android】Android 学习记录贴

    官网 教程学习笔记 Genymotion 安卓虚拟器太慢,用Genymotion(装载eclipse的插件) 利用Genymotion运行Android应用程序 1.首先,点击 来启动或者创建您要使用 ...

  4. Java中数据库连接池原理机制的详细讲解(转)

    连接池的基本工作原理 1.基本概念及原理 由上面的分析可以看出,问题的根源就在于对数据库连接资源的低效管理.我们知道,对于共享资源,有一个很著名的设计模式:资源池 (Resource Pool).该模 ...

  5. JDBC 1 利用Statement对数据库进行增删改查

    准备工作 1新建po类:User private int id; private String name; private String pwd; set,get方法省略 2  新建UserDao类, ...

  6. Servlet概念入门

    什么是Servlet Servlet 为创建基于 web 的应用程序提供了基于组件.独立于平台的方法,可以不受 CGI 程序的性能限制.Servlet 有权限访问所有的 Java API,包括访问企业 ...

  7. php 两种或的区别 or ||

    php 两种或的区别 or || 实验代码. <?php $p = 999 or 1; var_dump($p); $q = 999 | 1; var_dump($q);

  8. Maven项目合并

    当多个项目之间有关联.依赖jar包有重复时,可以考虑进行合并.举例,我一开始有一个test-pilling项目,pom文件如下: <project xmlns="http://mave ...

  9. python3 之 linux命令实现

    os.mkdir(path[, mode]) 以数字mode的mode创建一个名为path的文件夹.默认的 mode 是 0777 (八进制) # 创建多级目录 mkdir -p dir1/dir2 ...

  10. new JSONObject()报错

    如果缺少下列依赖包会报错: 1.commons-beanutils-1.7.0.jar 2.commons-collections-3.2.1.jar 3.commons-lang-2.3.jar 4 ...