zoukankan      html  css  js  c++  java
  • hdu 1551 Cable master (二分法)

    Cable master

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 1428    Accepted Submission(s): 522


    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 input consists of several testcases. The first line of each testcase contains two integer numbers 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 centimeter and at most 100 kilometers in length. All lengths in the input are written with a centimeter precision, with exactly two digits after a decimal point.

    The input is ended by line containing two 0's.
     
    Output
    For each testcase write to the output 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 must contain the single number "0.00" (without quotes).
     
    Sample Input
    4 11 8.02 7.43 4.57 5.39 0 0
     
    Sample Output
    2.00
     
    Source
     
    Recommend
    LL   |   We have carefully selected several similar problems for you:  2333 2298 1399 2446 2289 
     
     1 //187MS    320K    650 B    G++
     2 /*
     3 
     4     题意:
     5         给你n块木板,长为ai,要用这些木板分成k块等长的木板,问最长可为多长
     6         
     7     二分法:
     8         和之前某题一样的想法,就是计算出当长度为x时可得到的木板块数是否符合
     9     然后几时二分的思想做。 
    10 
    11 */
    12 #include<stdio.h>
    13 #include<string.h>
    14 double a[10005];
    15 int n,k;
    16 int fac(double x)
    17 {
    18     int cnt=0;
    19     for(int i=0;i<n;i++)
    20         cnt+=(int)(a[i]/x);
    21     return cnt;
    22 }
    23 int main(void)
    24 {
    25     while(scanf("%d%d",&n,&k),n+k)
    26     {
    27         double l=0;
    28         double r=0;
    29         for(int i=0;i<n;i++){
    30             scanf("%lf",&a[i]);
    31             r+=a[i];
    32         }
    33         r/=k;
    34         while(r-l>=0.00001){
    35             double mid=(r+l)/2;
    36             int m=fac(mid);
    37             if(m>=k) l=mid;
    38             else if(m<k) r=mid;
    39         }
    40         //printf("%d
    ",fac(r));
    41         printf("%.2lf
    ",l);
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    access denied for user 'root'@'localhost'(using password:YES) FOR WINDOWS
    PKU 1001解题代码
    PKU 1002解题总结
    为什么vue组件data必须是函数
    call 和 apply 区别
    CSS|Stacking context 堆叠上下文
    Vue3.0 tsx 函数组件
    js中的变量提升
    JavaEE|架构
    MVC,MVP 和 MVVM
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3455928.html
Copyright © 2011-2022 走看看