ZOJ 3334 Body Check greedy algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.