Title: 10714-ants
On a board with a length of L, there are a lot of ants distributed. The positions of each ant will be given, but the direction will not be set. If the two ants meet, in the opposite direction. Ask the shortest time and longest time for all the ants to fall onto the board.
Solution: If the shortest time is used, each ant will move toward the nearest two ends. Finally, the shortest time is used to obtain the maximum value of the nearest position. In this case, the two ants will not be met, because the ant in front of an ant is either in the same direction or in the opposite direction; the ant in the latter is also in the same situation. So it won't happen.
The longest time is actually the time spent by the ant, which is the farthest from the two ends. Although the two ants may encounter this problem, if the two ants encounter this problem, they will move in the opposite direction, in this way, the ant who met him helped him finish the road he was going to take, which is equivalent to a relay. (It can be like this many times, but eventually it is still the distance that the ant wants to take from both ends, but it is just the end of the relay ).
Code:
# Include <stdio. h> const int n = 1000005; int s [N]; int max (const int X, const int y) {return x> Y? X: Y;} int min (const int X, const int y) {return x <Y? X: Y;} int main () {int t; int L, N; scanf ("% d", & T); While (t --) {scanf ("% d", & L, & N); For (INT I = 0; I <n; I ++) scanf ("% d ", & S [I]); int minlen, maxlen; minlen = maxlen =-1; for (INT I = 0; I <n; I ++) {minlen = max (minlen, min (s [I], L-s [I]); maxlen = max (maxlen, max (s [I], l-S [I]);} printf ("% d \ n", minlen, maxlen);} return 0 ;}