Cable Master
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 29554 |
|
Accepted: 6247 |
Description
Inhabitants of the Wonderland has decided to hold a regional programming contest. The judging committee has volunteered and have promised to organize the most honest contest ever. It is decided to connect computers for the contestants using a ' star ' topology-i.e. Connect them all to a single centra L Hub. To organize a truly honest contest, the Head of the judging committee have decreed to place all contestants evenly around T He hub on the equal distance from it.
To buy network cables, the judging committee have contacted a local network solutions provider with a request to sell for T Hem a specified number of cables with equal lengths. The judging committee wants the cables to being as long as possible to sit contestants as far from each other as possible.
The Cable Master of the company is assigned to the task. He knows the length of each cable in the "stock up" Centimeter,and he can cut them with a centimeter precision being to LD the length of the pieces he must cut. However, this time, the length was not known and the Cable Master is completely puzzled.
The Cable Master, by writing a program that would determine the maximal possible length of a Cable piece th At can is cut from the cables in the stock, to get the specified number of pieces.
Input
The first line of the input file contains the 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 the requested pieces. The first line was followed by N lines with a number per line, which specify the length of each cable in the the stock in Mete Rs. All cables is at least 1 meter and at the most of the kilometers in length. All lengths in the input file is written with a centimeter precision, with exactly, and digits after a decimal point.
Output
Write to the output file, the maximal length (in meters) of the pieces, Cable Master may cut from the cables in the STO CK to get the requested number of pieces. The number must is written with a centimeter precision, with exactly, and digits after a decimal point.
If It isn't possible to cut the requested number of pieces each one being at least one centimeter long and then the output F Ile must contain the single number "0.00" (without quotes).
Sample Input
4 118.027.434.575.39
Sample Output
2.00
1, do not know why on the POJ with g++ submission is wrong, submitted in C + + can be, in Hangzhou electric DIY also can not be too
2, the beginning has been wrong, looked at the other people's work, found that the original does not have to put all the cables are used as data
2 2
1.02
2.33
The answer is 1.16.
3, there is to pay attention to the final result is not rounding, but directly take the decimal place after two
#include <stdio.h> #include <string.h> #define MAX 10100#define maxn (x, y) (x>y?x:y) double a[max];int n,m; int num (double x)//Calculate the maximum number of segments at x length to do this { //solves the problem that all cables are not necessarily used int i,sum=0;for (i=1;i<=n;i++) {sum+= (int) (a[i]/x) ;} return sum;} int main () {int i;while (scanf ("%d%d", &n,&m)!=eof) {memset (a,0,sizeof (a));d ouble max=0,suma=0;for (i=1;i<= n;i++) {scanf ("%lf", &a[i]); MAX=MAXN (Max,a[i]); suma+=a[i];} if (suma/m<0.01) printf ("0.00\n"), else{double l=0.01,r=max,mid=0;while (r-l >1e-8) {mid= (l+r)/2.0;if (Num (mid) >=m) L=mid;elser=mid;} int tem=r*100;double ans=tem*0.01;printf ("%.2lf\n", ans);}} return 0;}
POJ 1064 Cable Master "floating-point binary search"