Cable Master
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 28764 |
|
Accepted: 6091 |
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
Source
Northeastern Europe 2001
Title Link: http://poj.org/problem?id=1064
The main topic: There are n rope, each long with a precision of 0.01 of the real number, now to divide all into equal length of k, ask the longest is how much
Topic Analysis: A typical two-part problem, you can directly two decimal places, but not recommended, two decimal places have a lot of details bad handling, Direct. 2f seems to automatically round up, because the topic is to keep two-bit, directly by 100 converted to an integer two points, the final output of the time except 100.0, so seemingly will not be rounded.
#include <cstdio> #include <algorithm>using namespace Std;int a[10005];int N, k;bool ok (int m) {int cnt = 0;
for (int i = 0; i < n; i++) cnt + = a[i]/m; return CNT >= k;} int main () {while (scanf ("%d%d", &n, &k)! = EOF) { int ma = 0; for (int i = 0; i < n; i++) { double tmp; scanf ("%lf", &tmp); A[i] = (int) (TMP *); MA = Max (MA, a[i]); } int r = ma, l = 1; while (L <= R) { int mid = (L + r)/2; if (OK (mid)) L = mid + 1; else r = mid-1; } Note that the answer here is R is not L, because CNT is less than K is eligible, greater than K does not meet the conditions of printf ("%.2f\n", (double) r/100.0);} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 1064 Cable master (binary fractional integer)