题意:一群蚂蚁走在一条长度为L 公分的绳子上,每只蚂蚁的速度为1 cm/sec。当一只蚂蚁走到绳子的尽头时,它马上掉下绳子(再也爬不起来了)。当两只蚂蚁在绳子上相遇时,马上掉头往另一个方向走去。我们知道每只蚂蚁在绳子上的位置,但不幸的是,我们并不知道每只蚂蚁开始时走的方向。你的任务是算出最快和最慢可能需要多少时间,所有的蚂蚁都掉出绳子外。
方法:经典的蚂蚁问题,最短的时间是两边的蚂蚁分别往两边走的情况,时间为离中间最近的蚂蚁到两边的距离。最长时间为蚂蚁距离远的那一端距离的最大值,只考虑两头的蚂蚁就行。蚂蚁相撞等于对穿而过。
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;
const int maxn = 1000000+10;
int pos[maxn];
int main()
{
#ifdef Local
freopen("a.in", "r", stdin);
#endif
int t = 0;
cin >> t;
for(int kase = 1; kase <= t; kase++)
{
int p = 0;
memset(pos, 0, sizeof(pos));
int L = 0, n &#