简单题。
最短的好想,都向自己临近的一端走就行了。
最长的呢?仔细一想就会发现即使两只蚂蚁相遇了,反向了,跟原来的情况还是一样的,所以最长的情况就是都向自己临着远的一端走。
求所有蚂蚁掉出的时间所以只需要算走得最长的那只蚂蚁用的时间即可。
看起来很复杂,其实连数组都可以不用开。。
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int L,n;
scanf("%d%d",&L,&n);
int sh=0,lo=0;
int cur;
while(n--)
{
scanf("%d",&cur);
if(cur<L/2)
{sh=max(sh,cur);lo=max(lo,L-cur);}
else
{sh=max(sh,L-cur);lo=max(lo,cur);}
}
printf("%d %d\n",sh,lo);
}
return 0;
}