Usacao Milking Cows segment tree

Source: Internet
Author: User

Background: I used the minimum efficiency of the violence to simulate, unexpectedly built a 1000000 array, the paper said that as long as the calculation amount of not more than 2000000 can be passed.

Learning: 1. For me this method can be improved, that is, the beginning and end of the data Duraton to sort, let after 1 instead of the smallest, 2 instead of the second small, 3 instead of ... Then take the 1,2,3,4,5 ... to simulate the operation and then restore back to the interval length, which improves a lot of efficiency. But simulation is not the best efficiency, it is necessary to the already abstract 1,2,3.,4 ... with a line segment tree (insert:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/2464583. HTML (knowledge of Segment tree in ACM))

2. You can consider sorting by the left boundary after the interval merge operation (it is easier to judge when merging)

Experience: Citing last week's training lesson Seniors said: A lot of data we will find a surprise after him !

My Code of Violence:

/*id:jibancan1lang:c++task:milk2*/#include <stdio.h> #define Maxline 1000000int str[maxline];int main (void) {      freopen ("milk2.in", "R", stdin), Freopen ("Milk2.out", "w", stdout), int n,min=maxline,max=0;scanf ("%d", &n); for (int i=0;i<n;i++) {int start,end;scanf ("%d%d", &start,&end), and for (int j=start;j<end;j++)    str[j]+ +;if (start<min) min=start;if (End>max) max=end;    } int cout0=0,cout1=1,an0=0,an1=0;//0 mean no one is milking, 1 means the oppose.for (int k=min;k<max;k++)//find the Longs T no and yes milking interval. {if (str[k+1]>0) {   if (cout0>an0) an0=cout0;   cout0=0;   cout1++;} Else{if (Cout1>an1) an1=cout1;cout1=0;cout0++;}} printf ("%d%d\n", an1,an0); return 0; }   


Usacao Milking Cows segment tree

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.