acm 2 1007 Cable master

1.1007

2.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

3.问题描述
仙境的居民决定举行一次区域性的节目比赛。评审委员会已经自愿,并承诺组织最诚实的比赛。这是决定使用一个“星”拓扑连接计算机的选手-即连接到一个单一的中心枢纽。组织一个真正诚实的比赛,评审委员会的头已经下令将所有参赛者均在轮毂上相等的距离。
为购买网络电缆,评审委员会已联系当地网络解决方案供应商,要求向其出售数量相等的电缆。评审委员会要尽可能长时间地坐在一起,尽可能地坐在一起,尽可能地坐在一起的选手。
该公司的电缆船长被分配到任务。他知道每根电缆的长度都在一厘米左右,他可以用厘米高的精度来切割,他必须切。但是,这个时候,长度是不知道和电缆的主人是完全困惑。
你是帮助电缆的主,通过编写一个程序,将确定一个电缆的最大可能长度,可从电缆的电缆,以获得指定数量的作品。
输入
输入包含多个测试用例。每个测试用例的第一行包含两个整数n和k,用一个空格隔开。N(1≤N≤10000)是在股票电缆的数量,和K(1≤K≤10000)是请求的数量。第一条线与一条线的一个数,即指定在股票的每根电缆的长度。所有电缆的长度至少为1厘米,长度为100公里。输入的所有长度都写着一个厘米精度,在小数点后准确2个数字。
输入的结束是由线包含0的。
输出
对每个测试用例输出的最大长度(米)的棋子,电缆主可能会减少在股票电缆得到件所要求的数量。这个数字必须用一个厘米高的精度书写,用小数点后准确2个数字。
如果不能够把每一个至少一厘米长的段,然后输出必须包含单个数字“0”(没有引号)。
Sample Input
4 11
8.02
7.43
4.57
5.39
0 0
 Sample Output
2.00

4.电缆问题,其实就是绳子问题,明显的二分&三分,n条绳子,分成11份,求最长

5.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define exp 1e-8


int n,k;
double a[10005],sum;


int judge(double s)
{
    int cnt = 0;
    for(int i = 0; i<n; i++)
    {
        cnt+=(int)(a[i]/s);
    }
    if(cnt>=k) return 1;
    return 0;
}


int main()
{
    int i;
    while(~scanf("%d%d",&n,&k),n+k)
    {
        sum = 0;
        for(i = 0; i<n; i++)
        {
            scanf("%lf",&a[i]);
            sum+=a[i];
        }
        sum = sum/k;
        double l = 0,r = sum;
        while(fabs(l-r)>exp)
        {
            double mid = (l+r)/2;
            if(judge(mid))
                l = mid;
            else
                r = mid;
        }
        printf("%.2f\n",l);
    }


    return 0;
}
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值