poj -1852 ants (思维题)
2015-02-02 15:42
316 查看
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 ; 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; }
相关文章推荐
- 【思维】POJ 1852 Ants
- poj-1852-Ants【思维】
- poj 1852 ants 思维题
- POJ 1852 Ants(思维)
- POJ 1852 Ants (蚂蚁_思维转换,水题)
- 简单思维题 poj 1852 Ants
- POJ 1852 Ants 思维题
- poj 1852 Ants 【思维】
- poj 1852 Ants(思维题)
- POJ 1852 Ants 思维题 简单题
- 【POJ - 1852】 Ants 【思维】
- poj 1852 Ants (思维)
- POJ 1852 Ants (思维技巧 + 贪心)
- [POJ1852]Ants
- POJ-1852-Ants
- POJ 1852 Ants 蚂蚁
- poj 1852 Ants 发现问题,解决问题
- POJ 1852 Ants
- 思维题-POJ1852-挑战程序设计2
- POJ1852 Ants (蚂蚁落杆)