标签:思维题
n只蚂蚁以每秒1cm的速度在长为Lcm的杆子上爬行,当蚂蚁爬到杆子的端点时就会掉落,由于杆子太细,两只蚂蚁相遇时,他们不能交错通过,只能各自反向爬回去,对于每只蚂蚁,我们知道它距离杆子左端的距离为x,但不知道它当前的朝向,请计算所有蚂蚁落下杆子所需的最短时间很最长时间。
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <string> #include <set> #include <functional> #include <numeric> #include <sstream> #include <stack> #include <map> #include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long #define inf 0x7f7f7f7f #define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define pi acos(-1.0) #define L(x) (x) << 1 #define R(x) (x) << 1 | 1 #define MID(l, r) (l + r) >> 1 #define Min(x, y) (x) < (y) ? (x) : (y) #define Max(x, y) (x) < (y) ? (y) : (x) #define E(x) (1 << (x)) #define iabs(x) (x) < 0 ? -(x) : (x) #define OUT(x) printf("%I64d\n", x) #define lowbit(x) (x)&(-x) #define Read() freopen("a.txt", "r", stdin) #define Write() freopen("dout.txt", "w", stdout); #define N 1000005 using namespace std; int f[N]; int main() { // freopen("a.txt","r",stdin); int t,l,n,i; scanf("%d",&t); while(t--) { scanf("%d%d",&l,&n); for(i=0;i<n;i++) scanf("%d",&f[i]); int minn=0; for(i=0;i<n;i++) { minn=max(minn,min(f[i],l-f[i])); } int maxn=0; for(i=0;i<n;i++) { maxn=max(maxn,max(f[i],l-f[i])); } printf("%d %d\n",minn,maxn); } return 0; }
标签:思维题
原文地址:http://blog.csdn.net/u012773338/article/details/43409219