1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 #defineSC (x) scanf ("%d",& (x))6 #defineSC2 (x, y) scanf ("%d%d", & (×), & (Y))7 #definePF (x) printf ("%d\n", X)8 #definePF2 (x, y) printf ("%d%d\n", X, y)9 #definefor (I,b,e) for (i=b; i<=e; i++)Ten #defineCL (x, y) memset (x,y,sizeof (×)) One Const intMAX =1000000; A intAnt[max], Min[max]; - using namespacestd; - intMainintargcChar*argv[]) { the intT, L, N, I, K, Max; - SC (T); - while(t--){ -Max =0; K =0; +CL (Min,0); - SC2 (L, n); +for (I,0, N-1) SC (ant[i]); ASort (ant, ant+n); atmax = ant[n-1] > (l-ant[0]) ? ant[n-1]: (l-ant[0]); -for (I,0, N-1){ - if(Ant[i] <= L/2){ -min[k++] =Ant[i]; - } - Else{ inmin[k++] = LAnt[i]; - } to } +Sort (Min, min+k); -PF2 (min[k-1], max); the } * return 0; $}View Code
/* 1. Fastest: Find the closest point to the middle, and the time it takes to get to the nearest endpoint is the time for all the ants to fall 2. Slowest: For each point, find out that the farthest distance to the two endpoints is the time that all the ants fall .
POJ 1852 Ants