【題解】UVA 10714 Ants

【題目敘述】https://vjudge.net/problem/UVA-10714

  • a[i] = {left, right}:第 i 隻螞蟻距離棍子左邊和右邊的距離
  • Line-16:所有螞蟻跌落棍子的最短時間
  • Line-17:所有螞蟻跌落棍子的最長時間
#include <iostream>
using namespace std;

int main() {
    int T, l, n, x;
    cin >> T;
    while (T--){
        cin >> l >> n;
        pair<int,int> a[n];
        for (int i = 0; i < n; i++){
            cin >> x;
            a[i] = {x, l - x};
        }
        int mn = 0, mx = 0;
        for (int i = 0; i < n; i++){
            mn = max(mn, min(a[i].first, a[i].second));
            mx = max(mx, max(a[i].first, a[i].second));
        }
        cout << mn << " " << mx << "\n";
    }
    return 0;
}
分享本文 Share with friends