Question connection: 10714-ants
There are n ants on a stick. These ants can start to move in one direction, either left or right, at the same speed, however, once an ant encounters another ant, the two will immediately change their direction and move in the opposite direction. Find the minimum and longest time for all ants to leave the wooden stick.
Solution: in fact, the two ants in the question may be confused, because at first all the ants are moving in one direction, and the speed is the same, and it is impossible to catch up with each other, so you don't have to consider just one point. In this way, you only need to calculate the maximum time to left and right respectively. The maximum time is the maximum time, and the minimum time is the minimum time (which can be summed up)
# Include <stdio. h> int max (const Int & A, const Int & B) {return A> B? A: B;} int min (const Int & A, const Int & B) {return A> B? B: A;} int main () {int cas, N, Len, Max, Min, DIST; scanf ("% d", & CAS); While (CAS --) {max = min = 0; scanf ("% d", & Len, & N); For (INT I = 0; I <n; I ++) {scanf ("% d", & Dist); max = max (Max, Max (Dist, len-Dist); min = max (Min, min (Dist, len-Dist);} printf ("% d \ n", Min, max);} return 0 ;}