http://poj.org/problem?id=1852
两只蚂蚁相遇后相反方向走,等于两只蚂蚁相遇后不转向继续向前走,算蚂蚁距端点的距离即可
数据量较大,要用scanf读入,或者用cin加速
1 2 |
ios::sync_with_stdio(false); cin.tie(0); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define INF 0x3F3F3F3F void solve() { int len, n; cin >> len >> n; int a[n]; for(int i = 0; i < n; i++) cin >> a[i]; int mint = 0, maxt = 0; for(int i = 0; i < n; i++) mint = max(mint, min(a[i], len - a[i])); for (int i = 0; i < n; i++) maxt = max(maxt, max(a[i], len - a[i])); cout << mint << " " << maxt << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; while(n--) solve(); return 0; } |