This is actually a simple simulation, but our first turn is over, later seniors Rejudge, we again tle, this look not only delayed our time, also fluctuation to our mood, the original time is 2s, (the original OJ is 2s), and then changed to 1s, I used the O (n*n) cycle directly timed out , this is not scary, we are misled by this idea, has been optimized on the basis of O (N*n), made several times .... Finally know that is not so complicated, the problem of the sample is very special, after the direct O (N) enumeration can be, because the water penalty when more, ranked particularly by the back, my heart good pain t ....
#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;structedge{intSt,en;} e[100010];BOOLCMP (EDGE A,edge b) {returnA.St <B.st;}intMain () {intT; scanf ("%d",&t); for(inti =0; I < t;i++) {scanf ("%d%d",&e[i].st,&e[i].en); } sort (E,e+t,cmp); intAns =0; EDGE Now= e[0]; for(inti =1; I < t;i++) { if(E[i].en <Now.en) {ans++; } Elsenow =E[i]; } printf ("%d\n", ans); return 0;}
CF History Problem Solving report