UVA 10714 Ants
贪心,蚂蚁间的掉头相当于穿过,所以以中间为区分点,时间最短时是左边的往左走,右边的往右走,时间最长时是左边的往右走,右边的往左走
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #define maxn 1000000 5 6 using namespace std; 7 8 int T,mint,maxt,n,l; 9 int main() 10 { 11 scanf("%d",&T); 12 while(T--) 13 { 14 scanf("%d%d",&l,&n); 15 int mid=l/2,a; 16 mint=0,maxt=0; 17 for(int i=0;i<n;i++) 18 { 19 scanf("%d",&a); 20 if(a>mid) 21 { 22 maxt=max(maxt,a); 23 mint=max(mint,l-a); 24 } 25 else 26 { 27 maxt=max(maxt,l-a); 28 mint=max(mint,a); 29 } 30 } 31 printf("%d %d\n",mint,maxt); 32 } 33 return 0; 34 }