HDU 5214 Movie (competition code "BestCoder" cup Chinese College Students' Program Design champion)
On May Day, I had the honor to go to hangdian with my teacher to seek abuse, wait for the great AK of Tsinghua University and other giants, sum up experience, and inspire me to move forward!
[Question link]Click here ~~
【Theme] In multiple uncertain intervals, I asked if I could select three different intervals.
【Solutions]
Ps: At that time, it was the hjs question. After the question was knocked out, all three people checked it and found that there was no problem, but the question was handed in with CE, followed by various calls and errors, finally, we found that the modulo was removed, and it was a tragedy to determine whether a certain interval exists in the middle of an existing interval without crossover...
[Official solution report] First, we should consider how to select the leftmost interval. If the leftmost interval is I, the left endpoint of the other two intervals must be greater than Ri, if j exists outside of I The modulo value of this question is very special. The natural overflow of unsigned int can achieve the same effect, and the time complexity O (N)
Code:
# Include
Using namespace std; const int N = 1e7 + 10; const int inf = 0x3f3f3f; struct node {unsigned int pre, last;} Map [N]; int main () {int T, n; unsigned int L1, R1, a, B, c, d, maxx, minn; bool flag; scanf ("% d", & T ); while (T --) {flag = false; cin> n> L1> R1> a> B> c> d; maxx = 0; minn = inf; Map [0]. pre = L1; Map [0]. last = R1; for (int I = 1; I
Map [I]. last) swap (Map [I]. pre, Map [I]. last); // switch after all processing! If (Map [I]. pre> maxx) maxx = Map [I]. pre; // the maximum range of the Left endpoint is used as the rightmost range. if (Map [I]. last
Minn) {puts ("YES"); flag = true; break ;}} if (! Flag) puts ("NO");} return 0 ;}