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;
}


目录
相关文章
|
人工智能
POJ3104---烘干机
POJ3104---烘干机
Dungeon Master
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all
126 0
|
算法 人工智能
初试DFS之HDU1016
DFS和BFS是基础算法,可怜我现在才开始接触,不争气......
1877 0
1253 Dungeon Master
题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms  内存限制: 65536kB 描述 You are trapped in a 3D dungeon and need to...
1730 0