Usaco Milking Cows

Source: Internet
Author: User

Test instructions is a time for you to milk a worker and then let you find the longest continuous working time and the longest continuous non-working time. After discretization, you can simply sweep it once:

/*id:m1500293 lang:c++ prog:milk2*/#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intN;intx[2* the+ -];intnum;structperson{intx, y; BOOL operator< (ConstPERSON&AMP;R)Const    {        returnX <r.x; }}; Person per[ the+Ten];BOOLJudgeintX1,intx2) {     for(intI=0; i<n; i++)    {        if(Per[i].x<=x1 && per[i].y>=x2)return true; }    return false;}intMain () {Freopen ("milk2.in","R", stdin); Freopen ("Milk2.out","W", stdout);  while(SCANF ("%d", &n) = =1) {num=0;  for(intI=0; i<n; i++)        {            intx1, x2; scanf ("%d%d", &x1, &x2); per[i].x=x1; per[i].y=x2; X[num++] =X1; X[num++] =x2; } sort (x, x+num); Num= Unique (x, X+num)-x; Sort (per, per+N); intmaxwk=0, maxfe=0; inttpwk=0, tpfe=0;  for(intI=0; i<num-1; i++)        {            if(Judge (X[i], x[i+1]))//belongs to working hours{tpwk+ = x[i+1] -X[i]; Maxfe=Max (Maxfe, TPFE); TPFE=0; }            Else{TPFE+ = x[i+1] -X[i]; Maxwk=Max (MAXWK, TPWK); Tpwk=0; }} Maxfe=Max (Maxfe, TPFE); Maxwk=Max (MAXWK, TPWK); printf ("%d%d\n", Maxwk, Maxfe); }    return 0;}

Usaco Milking Cows

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.