博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ants(思维)
阅读量:6210 次
发布时间:2019-06-21

本文共 1747 字,大约阅读时间需要 5 分钟。

Ants
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 12893   Accepted: 5637

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

210 32 6 7214 711 12 7 13 176 23 191

Sample Output

4 838 207 题解:水题,就是一个木棒在水里,蚂蚁在这个木棒上可以右走,也可以左走,1cm/s,问最小最大多长时间都掉到水里; 代码:
#include
#include
#include
#include
using namespace std;const int MAXN=1000010;int a[MAXN];int main(){ int T,l,n,x,mx; scanf("%d",&T); while(T--){ scanf("%d%d",&l,&n); mx=-1; for(int i=0;i

  

转载地址:http://vobja.baihongyu.com/

你可能感兴趣的文章
HBASE的Java与Javaweb(采用MVC模式)实现增删改查附带源码
查看>>
初识HTML
查看>>
Android开发之资源文件存储
查看>>
让Spring不再难懂-ioc篇
查看>>
LeetCode----172. Factorial Trailing Zeroes(Java)
查看>>
乱七八糟记一下
查看>>
Python爬虫与一汽项目【二】爬取中国东方电气集中采购平台
查看>>
angular微信支付url未注册
查看>>
django-2-目录结构
查看>>
list去重的几种方法
查看>>
期货开平,多开,空开,多平,空平
查看>>
c# WF 第3节 窗体的属性
查看>>
Eclipse在线安装SVN
查看>>
2、DTO(数据传输对象)
查看>>
dubbo之泛化实现
查看>>
python (winpython) 下载地址
查看>>
MD5加密
查看>>
哈夫曼编码测试
查看>>
flask_web开发这本书的学习笔记
查看>>
华为云【安全组】开放所有端口
查看>>