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