HDU-1551-Cable master

简介: HDU-1551-Cable master





Cable master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 183   Accepted Submission(s) : 34

Problem 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      


题目分析:

4 11  

8.02  

7.43  

4.57  

5.39

意思是有4段电缆 现在要把它分成11段 问最长的分发

正好 8.02 / 2 =4   7.43 / 2=3   4.57 / 2 =2   5.39/  2=2     4+3+2+2=11 段

就这个意思 那么这个 2.00 就要用二分查找来确定了    

#include<cstdio>
#include<cstring>
int n,m;
double a[10010];
bool f(double x)
{
    int i,sum=0;
    for(i=0;i<n;i++)
        sum+=(int)(a[i]/x);
    return sum>=m;
}// 此处是把每个输入的数据进行除以x   这个x就是要把每段分成的长度
int main()
{
    int i;
    scanf("%d%d",&n,&m);
        for(i=0;i<n;i++)
           scanf("%lf",&a[i]);
        double l=0,r=1001000,mid;//  题上说  x的长度可以是 0 ---100千米   此处所给数据都是米 所以  r  应写成米
        while(r-l>1e-8)
        {
            mid=(r+l)/2;
            if(f(mid))  l=mid;
            else  r=mid;
        }
        r=(int)(r*100)/100.0; // 二分的最终结果保留两位数可能是一个 小数  此处样例的结果就是  2.01  但是数据结果是 2   所以此处要处理一下
        printf("%.2f\n",r);
    return 0;
}


目录
相关文章
|
并行计算 Java JavaScript
HDU 1010 Tempter of the Bone【DFS经典题+奇偶剪枝详解】
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 125945    Accepted Submis...
1230 0
|
算法 存储
【HDU 4547 CD操作】LCA问题 Tarjan算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4547 题意:模拟DOS下的cd命令,给出n个节点的目录树以及m次查询,每个查询包含一个当前目录cur和一个目标目录tar,返回从cur切换到tar所要使用的cd命令次数: 注意这里的cd命令是简化版,只能进行如下两种操作:   1.
977 0
|
机器学习/深度学习
【HDU 4452 Running Rabbits】简单模拟
两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时)、初始方向dir(E、N、W、S)和左转周期turn(小时/次)。 各自每小时往E、N、W、S中一个方向跑speed格,每隔turn小时左转一次(即逆时针的下一个方向)。
803 0