1 EG: POJ Ants P1007 single-plank bridge
Army ants horizontal length lcm walking pole, each having a constant velocity 1cm / s of. When reaching the end of a rod ant walking, it immediately falling. When two ants meet, they returned and began walking in the opposite direction. We know that ants original position on the pole, unfortunately, we do not know the direction of ants walking. Your task is to calculate all the ants from the shortest and the longest possible time required for the pole.
Analysis: As each ant speed equal, between ants are exactly the same, two ants met then reverse, can be seen as continue to move forward after the encounter, then all the ants from the pole shortest possible time, is each ants along the longest time period from the bar near the walking, the longest time all the ants from the pole, is the maximum time period of each ant along the rod from far away.
a = max (min (v [i] - 0 , l + 1 - v [i]), a); mash = max (max (v [i] - 0 , l + 1 - v [i]), mash)
2 EG: Luogu P1367 ants
for ( int I = . 1 ; I <= n-; I ++ ) { CIN >> K [I] II.A >> K [I] .B; R & lt [I] = K [I]; R & lt [I] .order = I; K [I] II.A + T * = K [I] .B; R & lt [I] .bump = K [I] .bump = 0 ; } Sort (K + . 1 , K + . 1 + n-, CMP); // by sorting final position Sort (R & lt +. 1, n-R & lt + +. 1, CMP); // Sort the initial position for ( int I = . 1 ; I <= n-; I ++ ) { K [I] .order = R & lt [I] .order; //得到初始位置的顺序 } for(int i=1;i<=n;i++){ if(k[i].a == k[i+1].a) k[i].bump = 1,k[i+1].bump = 1; } sort(k+1,k+1+n,cmpp); for(int i=1;i<=n;i++){ if(k[i].bump) printf("%d 0\n",k[i].a); else printf("%d %d\n",k[i].a,k[i].b); }