Main topic:
There are m doctors and n patients, each patient is known to check the body time. The doctor must work at the same time or only one person to find out the minimum time to check all patients. (At the same time a patient can only be examined by a doctor, and the doctor can only check a patient, but the doctor may substitute if the patient has not finished the examination.)
Ideas:
The time to check all the patients is related to the time of the doctor working together, the patient examined the disease time is divided into two, one is the time of the examination, the rest is a doctor check the time, the answer is sum (patient check time)-(m) * Work together time + work together time.
You can work together for two minutes to meet sum (min (co-working time, Patient time required)) >m* common working time. It is guaranteed to be able to have so much common working time.
#include <cstdio> #include <cmath> #include <iostream>using namespace std;const double eps = 1e-8;int m, N;double Patient[1005];int Sig (double k) { if (fabs (k) <eps) return 0; return k>0?1:-1;} int main () { while (scanf ("%d%d", &m,&n)!=eof) { double sum = 0,maxx = 0; for (int i=0;i<n;i++) { scanf ("%lf", &patient[i]); Sum+=patient[i]; } Double L = 0,r = sum; Double ans = 0; while (SIG (R-l)) { Double user = 0;double mid = (l+r)/2; for (int i=0;i<n;i++) { user+=min (patient[i],mid); } if (Sig (User-mid*m) <0) R=mid; else{ L = mid; } } printf ("%.4lf\n", sum-r* (M-1));} }
ZOJ 3334 Body Check greedy algorithm