练习二1007

Cable master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit :65536/32768K (Java/Other)

Total Submission(s) : 28   Accepted Submission(s) : 12

Problem Description

Inhabitants of the Wonderlandhave decided to hold a regional programming contest. The Judging Committee hasvolunteered and has promised to organize the most honest contest ever. It wasdecided to connect computers for the contestants using a&quot;star&quot; topology - i.e. connect them all to a single centralhub. To organize a truly honest contest, the Head of the Judging Committee hasdecreed to place all contestants evenly around the hub on an equal distancefrom it.<br><br>To buy network cables, the Judging Committee hascontacted a local network solutions provider with a request to sell for them aspecified number of cables with equal lengths. The Judging Committee wants thecables to be as long as possible to sit contestants as far from each other aspossible.<br><br>The Cable Master of the company was assigned to thetask. He knows the length of each cable in the stock up to a centimeter, and hecan cut them with a centimeter precision being told the length of the pieces hemust cut. However, this time, the length is not known and the Cable Master iscompletely puzzled.<br><br>You are to help the Cable Master, bywriting a program that will determine the maximal possible length of a cablepiece that can be cut from the cables in the stock, to get the specified numberof pieces.<br>

 

 

Input

The input consists of severaltestcases. The first line of each testcase contains two integer numbers N andK, separated by a space. N (1 ≤ N ≤ 10000) is the number of cables in thestock, and K (1 ≤ K ≤ 10000) is the number of requested pieces. The first lineis followed by N lines with one number per line, that specify the length ofeach cable in the stock in meters. All cables are at least 1 centimeter and atmost 100 kilometers in length. All lengths in the input are written with acentimeter precision, with exactly two digits after a decimal point.<br><br>Theinput is ended by line containing two 0's.<br>

 

 

Output

For each testcase write to theoutput the maximal length (in meters) of the pieces that Cable Master may cutfrom the cables in the stock to get the requested number of pieces. The numbermust be written with a centimeter precision, with exactly two digits after adecimal point.<br><br>If it is not possible to cut the requestednumber of pieces each one being at least one centimeter long, then the outputmust contain the single number "0.00" (without quotes).<br>

 

 

Sample Input

411<br>8.02<br>7.43<br>4.57<br>5.39<br>00<br>

 

 

Sample Output

2.00<br>

 

 

Source

2001-2002 ACM NortheasternEuropean Regional Programming Contest

 

 

题意:

有n条绳子,分成11段相等的,问能使得最长为多长。

 

解题思路:

直接二分答案,看二分到的值能否被剪成至少k断。

 

 

#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

 

#define N 10000

#define exp 1.0e-9

 

int n,k;

double num[N],sum,result;

 

int Count(double len)

{

   int count = 0;

   for(int i = 0;i < n;i++)

       count += int(floor(num[i] / len));

   return count;

}

 

void SecondDiv()

{

   double low,mid,high;

   low = 0.0;

   high = sum;

   while(high - low > exp)

    {

       mid = (high + low) / 2;

       if(Count(mid) >= k)

       {

           result = mid;

           low = mid;

       }

       else

           high = mid;

    }

}

 

int main()

{

   while(scanf("%d %d",&n,&k) && n + k)

    {

       sum = 0.0;

       for(int i = 0;i < n;i++)

       {

           scanf("%lf",&num[i]);

           sum += num[i];

       }

       result = 0.0;

       SecondDiv();

       printf("%.2lf\n",result);

    }

   return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值