题目:
思路:蚂蚁相碰和不相碰的情况是一样的,相当于交换位置继续走。
代码:
#include <iostream> #include <cstdio> #include <math.h> using namespace std; typedef long long ll; int main() { int t; int l,n; int key; int low,high; cin >> t; while(t--){ cin >> l >> n; int mn = 0; int mx = 0; for(int i = 0;i < n; i++){ scanf("%d",&key); if(key < l/2){ low = key; high = l-key; }else{ low = l-key; high = key; } mn = max(low,mn); mx = max(high,mx); } cout << mn << " " << mx << endl; } return 0; } // writen by zhangjiuding