zoukankan      html  css  js  c++  java
  • Ants

    An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they turn back and start walking in opposite directions. We know the original positions of ants on the pole, unfortunately, we do not know the directions in which the ants are walking. Your task is to compute the earliest and the latest possible times needed for all ants to fall off the pole.

    Input

    The first line of input contains one integer giving the number of cases that follow. The data for each case start with two integer numbers: the length of the pole (in cm) and n, the number of ants residing on the pole. These two numbers are followed by n integers giving the position of each ant on the pole as the distance measured from the left end of the pole, in no particular order. All input integers are not bigger than 1000000 and they are separated by whitespace.

    Output

    For each case of input, output two numbers separated by a single space. The first number is the earliest possible time when all ants fall off the pole (if the directions of their walks are chosen appropriately) and the second number is the latest possible such time. 

    Sample Input

    2
    10 3
    2 6 7
    214 7
    11 12 7 13 176 23 191
    

    Sample Output

    4 8
    38 207

    百度翻译:一群蚂蚁在一根长l厘米的水平杆上行走,每根杆的速度恒定为1厘米/秒。当一只蚂蚁到达杆的末端时,
    它立刻从杆上掉下来。当两只蚂蚁相遇时,它们会转身向相反的方向走。我们知道蚂蚁在柱子上的原始位置,不幸的是,
    我们不知道蚂蚁行走的方向。你的任务是计算所有蚂蚁从极点上掉下来所需要的最早和最晚的可能时间。

    思路:如果两只蚂蚁在相遇时交换身份,那么蚂蚁就可以一直沿一个方向走,题目就很简单了,要注意求的是所有的蚂蚁下落的时间,
    一个蚂蚁落下的时间分为短时间和长时间,则最短时间应是所有蚂蚁落下的短时间的最大值,最长时间
    是所有蚂蚁落下时间的长时间的最大值。


     1 #include <iostream>
     2 #include <cstdio>
     3 #include <fstream>
     4 #include <algorithm>
     5 #include <cmath>
     6 #include <deque>
     7 #include <vector>
     8 #include <queue>
     9 #include <string>
    10 #include <cstring>
    11 #include <map>
    12 #include <stack>
    13 #include <set>
    14 #include <sstream>
    15 #define mod 1000000007
    16 #define eps 1e-6
    17 #define ll long long
    18 #define INF 0x3f3f3f3f
    19 using namespace std;
    20 
    21 int l,t,n;
    22 int main()
    23 {
    24     cin>>t;
    25     while(t--)
    26     {
    27         scanf("%d %d",&l,&n);
    28         int s;
    29         int mi=0;
    30         int ma=0;
    31         for(int i=0;i<n;i++)
    32         {
    33             scanf("%d",&s);
    34             mi = max(mi,min(l-s,s));
    35             ma = max(ma,max(l-s,s));
    36 
    37         }
    38         printf("%d %d
    ",mi,ma);
    39     }
    40 }
  • 相关阅读:
    双USB墙壁电源插座面板....制作详解-电子产品世界论坛
    公共充电站?不用守着手机充电了 | 爱范儿
    公司简介-远能电气
    连接器|网络滤波连接器|电脑连接器|RJ45变压器-华联威电子有限公司
    自己动手做简单移动电源
    移动电源市场有多乱?
    聚合物电池_百度百科
    电芯:聚合物的一定比18650更好_移动电源_移动电源评测-中关村在线
    图文:充电宝租借自助机现身江城_新浪财经_新浪网
    不按时归还,信用会有“污点”_新浪浙江_新浪网
  • 原文地址:https://www.cnblogs.com/mzchuan/p/11173953.html
Copyright © 2011-2022 走看看