SDAU课程练习2 1007

来源:互联网 发布:广联达清单计价软件 编辑:程序博客网 时间:2024/05/21 06:35

Cable master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 20   Accepted Submission(s) : 8
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 &quot;star&quot; 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.<br><br>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.<br><br>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.<br><br>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.<br>
 

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.<br><br>The input is ended by line containing two 0's.<br>
 

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.<br><br>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).<br>
 

Sample Input
4 11<br>8.02<br>7.43<br>4.57<br>5.39<br>0 0<br>
 

Sample Output
2.00<br>
 

Source
2001-2002 ACM Northeastern European Regional Programming Contest

 


题目大意:


分网线,四根线,十一个人。问最长网线。


思路:


正常二分,和分 pei 差不多。


感想:


天上有个星星!!  今天是清明节,然而感冒的我只能躲在被子里写博客。天呐撸。。。好可怜。


AC代码:


#include <cstdio>#include<iostream>#include<stdio.h>#include<vector>#include<algorithm>#include<numeric>#include<math.h>#include<string.h>#include<map>#include<set>#include<vector>#include<iomanip>using namespace std;int main(){    //freopen("r.txt","r",stdin);    int n,i,f,num;    double r,l,mid;    double rope[10005];    while(cin>>n>>f)    {        if(n==0&&f==0) break;        double sum=0;        for(i=0;i<n;i++)        {            scanf("%lf",&rope[i]);            sum+=rope[i];        }        l=0;r=sum/f;        while(r-l>0.0000001)        {            num=0;            mid=(l+r)/2;            for(i=0;i<n;i++)                num+=(int)(rope[i]/mid);            if(num<f)                r=mid;            else                l=mid;        }        printf("%.2f\n",l);    }}


0 0
原创粉丝点击