zoukankan      html  css  js  c++  java
  • OpenJ_Bailian 1852

     Ants

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Submit Status Practice OpenJ_Bailian 1852

    Description

    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

    题意:

           一些蚂蚁在木杆上爬行。给出木杆的长度(厘米)和每一只蚂蚁的在木杆上的坐标位置,蚂蚁只能选择一个方向匀速爬行,速度为每秒一厘米,蚂蚁相遇后各自掉头行驶。输出所有蚂蚁都掉下木杆的最短时间和最长时间。

    输入:

           情况数T,每个情况第一行输入长度和蚂蚁数量,之后一行输入每一只蚂蚁的位置。

    输出:

           最短时间和最长时间。

    分析:

           考虑所有蚂蚁都可以相互穿过。

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cmath>
     5 using namespace std;
     6 const int INF = 1e6;
     7 int main(){
     8     int T; scanf("%d",&T);
     9     while(T--){
    10         int len,n; scanf("%d%d",&len,&n);
    11         int mini = -1,maxi = -1;
    12         for(int i = 0 ; i < n ; i++){
    13             int x; scanf("%d",&x);
    14             int t1 = min(len - x,x);
    15             mini = max(t1,mini);
    16             int t2 = max(len - x,x);
    17             maxi = max(t2,maxi);
    18         }
    19         printf("%d %d
    ",mini,maxi);
    20     }
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    thinkphp模块设计
    thinkphp自动创建目录
    thinkphp入口文件
    thinkphp目录结构
    thinkphp环境要求
    获取ThinkPHP
    QueryList getData()方法中多次调用来实现递归多级采集。
    PHP count() 函数
    PHP mysqli_affected_rows() 函数
    QueryList 内容过滤
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5769349.html
Copyright © 2011-2022 走看看