Ants poj 1852
来源:互联网 发布:rnm网络是什么意思 编辑:程序博客网 时间:2024/06/10 03:22
Ants
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
code:
<span style="font-size:24px;">#</span><span style="font-size:18px;">include<iostream>#include<stdio.h>using namespace std;int main(){ int t,l,n,maxx,minn,i,a[100000]; scanf("%d",&t); while(t--) { scanf("%d%d",&l,&n); for(i=0;i<n;i++) scanf("%d",&a[i]); maxx=minn=0; for(i=0;i<n;i++) { minn=max(minn,min(a[i],l-a[i])); } for(i=0;i<n;i++) { maxx=max(maxx,max(a[i],l-a[i])); } printf("%d %d\n",minn,maxx); } return 0;}</span>
0 0
- poj 1852 Ants
- POJ 1852 Ants
- poj 1852Ants
- POJ 1852 Ants 蚂蚁
- POJ 1852 Ants
- POJ 1852 Ants
- POJ-1852-Ants
- POJ 1852 Ants
- [ACM] 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
- Ants(POJ 1852)
- Oracle的共享锁和排它锁
- html5(历史管理)
- servlet验证码
- popViewControllerAnimated 之后不走deallloc的几个原因:
- Java向前引用容易出错的地方
- Ants poj 1852
- JAVA : String StringBuilder String Buffer
- html5(历史管理)
- HTML布局和链接
- javascript 正则表达式
- ATTiny13单片机解433M超外差接收模块编码
- 【2015.4.7】心情贴
- 第五周 【项目3-用多文件组织多个类的程序】
- 在mysql客户端提示Access Denied的解决办法