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. 多线程实现方式---实现Runnable接口

    多线程实现方式---实现Runnable接口 一个类如果需要具备多线程的能力,也可以通过实现java.lang.Runnable接口进行实现.按照Java语言的语法,一个类可以实现任意多个接口,所以该 ...

  2. 如何发布二次开发后的openfire源码到linux服务器中

    这篇文章是在你已经down了openfire的源码,然后在本地跑起来了,再然后开发了一个自己的插件,想要发布到服务器上.ok这时候出现了一个问题,怎么才能发布到服务器上呢?别急往下看: 1.运行ant ...

  3. Git介绍及基本操作

    Git基本概念 在Git中,我们将需要进行版本控制的文件目录叫做一个仓库(repository),每个仓库可以简单理解成一个目录,这个目录里面的所有文件都通过Git来实现版本管理,Git都能跟踪并记录 ...

  4. [置顶] Android 关于BottomDialogSheet 与Layout擦出爱的火花?

    今天上班做那个类似于ios拍照的那种效果图 就是个垂直布局然后里面textview+分割线+textview+button 当然也可以用button+分割线+button 方法有很多,选择适合自己的就 ...

  5. HAWQ取代传统数仓实践(七)——维度表技术之维度子集

    有些需求不需要最细节的数据.例如更想要某个月的销售汇总,而不是某天的数据.再比如相对于全部的销售数据,可能对某些特定状态的数据更感兴趣等.此时事实数据需要关联到特定的维度,这些特定维度包含在从细节维度 ...

  6. mysql基础认识1

    一.配置文件 服务端和客户端的字符编码不一样时,可能会导致乱码显示等情况,为了统一两端的字符编码,可以通过配置文件进行实现,当然譬如登录账户等信息也可以进行配置,在启动mysql服务端时会自动读取配置 ...

  7. linux之管道

    1. 进程间通信概述 进程是一个独立的资源分配单元,不同进程之间的资源是独立的,没有关联,不能在一个进程中直接访问另一个进程的资源.进程不是孤立的,不同的进程需要进行信息的交互和状态的传递等,因此需要 ...

  8. GDI与OpenGL与DirectX之间的区别

    图形编程的几种技术对比: GDI,图形设备接口,MS开发的通用的windows系统图形编程接口,功能强涉及面广,一般的编程都用它.但是用来做多媒体开发就差强人意了 OPENGL是SGI开发的一套三维图 ...

  9. LeetCode Find Duplicate File in System

    原题链接在这里:https://leetcode.com/problems/find-duplicate-file-in-system/description/ 题目: Given a list of ...

  10. 两种方式创建Maven项目【方式一】

    经常使用maven进行项目的管理,今天整理两种方式创建maven项目及创建过程中碰到的问题怎么解决: 方式一: 1.新建maven项目,点击下一步. 2.勾选Create a simple proje ...