POJ 1852

POJ 1852

思维

把每只蚂蚁的相遇问题,直接看成穿过,这样对结果没有影响

最短时间是 所有蚂蚁都走完的时间,即所有蚂蚁走完的最小值中的最大值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define endl '
'
const int N = 1e6 + 10;
int t,len,n,x;
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> t;
    while(t --) {
        int maxi = 0,mini = 0;
        cin >> len >> n;
        for(int i = 0;i < n; ++i) {
            cin >> x;
            mini = max(mini,min(x,len - x)); 
            maxi = max(maxi,max(x,len - x));
        }
        cout << mini <<' ' << maxi << endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/lukelmouse/p/12427688.html