标签:ons end 实现 代码 通过 code while turn 不能
题意
n只蚂蚁以每秒1cm的速度在长为Lcm的杆子上爬行。当蚂蚁爬到杆子的端点时就会掉落。由于杆子太细,两只蚂蚁相遇时,它们不能交错通过,只能各自反向爬回去。对于每只蚂蚁,我们知道它距离杆子左端的距离x,但不知道它当前朝向。请计算所有蚂蚁下落的最短时间和最长时间。
题解
最长时间:在最大的下落时间里面选择最大的。
最短时间:在最小的下落时间里面选择最大的。
代码实现
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e6+10;
int a[maxn];
int main(void){
 int t;
 cin >> t;
 while(t--){
     int l,n;
     cin >> l >> n;
     int maxx = 0;
     int minx = 0;
     for(int i = 0; i < n; i++){
         cin >> a[i];
         maxx = max(maxx,max(a[i],l-a[i]));
         minx = max(minx,min(a[i],l-a[i]));
     }
     cout<<minx<<" "<<maxx<<endl; 
 }
 return 0;
} 标签:ons end 实现 代码 通过 code while turn 不能
原文地址:https://www.cnblogs.com/AC-AC/p/12290451.html