The main meaning of the topic is: There are n ropes, their lengths are Li, if they are cut out of the same length of K-bar rope, the length of each bar of the K-string what can be the longest?
This problem can be solved well by binary search.
The lengths are 0 to INF (INF is the largest possible number). Then the two-point search, the continuous narrowing of the range, cycle a certain number of times, can be a good answer to find out.
G++double to use%LF input, with%f output, C + + is the window, with%LF input, with%LF output.
The following is the code for AC:
#include <iostream> #include <cstdio> #include <cmath>using namespace std;const int INF = 10005;const int max_n = 10005;int N, k;double len[max_n];bool C (double x) {int num = 0;for (int i = 0; i < N; i++) {num + = (int) (len[i ]/x);} return num >= K;} void Solve () {Double lb = 0.0, UB = (double) INF * 10.0, mid;for (int i = 0; i < i++) //Loop 100 times, can be sufficient to solve {mid = (lb + UB)/2;if (C (mid)) lb = Mid;elseub = mid;} printf ("%.2f\n", Floor (UB *)/+); Note that this needs to be submitted in g++, and if it is a C + + submission, change to%.2LF. }int Main () {int i;while (scanf ("%d%d", &n, &k)! = EOF) {for (i = 0; i < N; i++) scanf ("%lf", &len[i]); solve ();} return 0;}
PKU acm1064--cable Master