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. LeetCode OJ:Rotate Image(旋转图片)

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  2. 解决Chrome关联HTML文件,图标不显示的问题。

    解决Chrome关联HTML文件,图标不显示的问题. 一.方法一 1.win+r,输入regedit,调出注册表信息,按下Ctrl+F,在注册表里搜索.在注册表里新建几个文件就可以了 a.新建Old ...

  3. 互联网公司面试必问的mysql题目(下)

    这是mysql系列的下篇,上篇文章地址我附在文末. 什么是数据库索引?索引有哪几种类型?什么是最左前缀原则?索引算法有哪些?有什么区别? 索引是对数据库表中一列或多列的值进行排序的一种结构.一个非常恰 ...

  4. LeetCode Minimum Time Difference

    原题链接在这里:https://leetcode.com/problems/minimum-time-difference/description/ 题目: Given a list of 24-ho ...

  5. 几个ADB常用命令

    http://blog.163.com/ymguan@yeah/blog/static/14007287220133149477594/ 1. 显示当前运行的全部模拟器:    adb devices ...

  6. JAVA单例模式:懒汉式,饿汉式

    今天复习了一下java的单例模式,写了懒汉式和饿汉式的实现例子.代码如下: 1.懒汉式单例 package com.lf.shejimoshi; /** * @classDesc: 类描述:(懒汉式单 ...

  7. MDK中STM32使用Printf函数详细解析【转载】

    在用MDK调试STM32板子串口时,为了方便串口调试,调用了printf()函数,用Keil仿真是,串口不能正确的输出,软件仿真时,总是卡在那 里.有点纳闷,然后调用USART_SendData()函 ...

  8. mysql 执行批量的sql

    <?xml version="1.0" encoding="utf-8" ?> <dbconfig> <!-- 数据库驱动 --& ...

  9. js练习题笔记

    javascrip测试题: 一.选择题(每题2分,多选题错选.少选不得分) 1.分析下段代码输出结果是( )    var arr = [2,3,4,5,6];    var sum =0;    f ...

  10. 深入浅出MFC学习笔记 消息

    本章将会对MFC的消息映射和 命令传递机制做深入探讨. MFC规定了消息传递的路线,消息会按照这个路线传递下去,找不到归宿的话就交给DefWindowProc. 在产生窗口之前,如果我们在创建窗口时指 ...