Ants
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 10722   Accepted: 4752

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

给你一堆蚂蚁,问全部蚂蚁掉下去的最少时间和最大时间
扫一遍就好
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
#define eps 1e-9
const int inf=0x7fffffff; //无限大
int x[maxn];
int main()
{
int t;
cin>>t;
while(t--)
{
int l,n;
scanf("%d%d",&l,&n);
int min_num=inf;
int max_num=;
int min_ans=;
int max_ans=;
for(int i=;i<n;i++)
{
scanf("%d",&x[i]);
min_num=min(x[i],l-x[i]);
//cout<<min_num<<endl;
min_ans=max(min_num,min_ans);
max_num=max(max_num,max(x[i],l-x[i]));
}
cout<<min_ans<<" "<<max_num<<endl;
}
return ;
}

poj 1825 Ants 水题的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  3. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  4. 最小费用最大流模板 poj 2159 模板水题

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15944   Accepted: 8167 Descr ...

  5. POJ 1837 Balance 水题, DP 难度:0

    题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...

  6. POJ - 3090 gcd水题

    大概题意就是求\(1 \le i,j \le n\)的\(gcd(i,j) = 1\)的个数+2(对于0的特判) 正解应该是欧拉函数或者高逼格的莫比乌斯反演 但数据实在太水直接打表算了 /*H E A ...

  7. POJ 1654 Area(水题)

    题目链接 卡了一下精度和内存. #include <cstdio> #include <cstring> #include <string> #include &l ...

  8. POJ 3080 (字符串水题) Blue Jeans

    题意: 找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个. 分析: 用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀. #include <cstdio> ...

  9. POJ 2365 Rope(水题)

    [题意简述]:给出我们钉子个数与半径,让我们求出缠绕在钉子上的绳子有多长. [分析]:从题目中我们能够看出,绳子长度的和等于每两个钉子的距离的和加上接触在钉子上的绳子的长度,不难发现这部分长度事实上就 ...

随机推荐

  1. aarch64_m2

    mingw32-leptonica-1.74.4-1.fc26.noarch.rpm 2017-06-12 17:20 1.0M fedora Mirroring Project mingw32-le ...

  2. sed实例收集

    url:http://blog.csdn.net/hepeng597/article/details/7852468 一.元字符集    1)^锚定行的开始 如:/^sed/匹配所有以sed开头的行. ...

  3. shell用户管理->

    用户的添加与删除练习 -> 脚本1(if then) 思路:1.条件测试, 脚本使用案例, 创建用户[交互式创建] 1.怎么交互式 read -p 2.接收到对应字符串怎么创建用户 userad ...

  4. 05 Diagnostics 诊断

    Diagnostics 诊断 Introduction 介绍 Profiling 分析 Tracing 跟踪 Debugging 调试 Runtime statistics and events 运行 ...

  5. Python开发环境(1):Eclipse+PyDev插件

    电脑:小米笔记本电脑Pro 15.6寸(i5-8250U),操作系统:Windows 10,JDK版本:1.8.0_152(环境变量已配置) Step 1.下载Eclipse 根据我的CPU型号,选择 ...

  6. python网络编程-socketserver

    一:socketserver简化了网络服务器的编写. 它有4个类:TCPServer,UDPServer,UnixStreamServer,UnixDatagramServer. 这4个类是同步进行处 ...

  7. thinkphp框架if标签条件表达式

    eq 等于neq 不等于gt 大于egt 大于等于lt 小于elt 小于等于

  8. OpenCV持久化(一)

    在OpenCV中,采用FileStorage类进行数据持久化,可以采用XML或YAML格式存储数据. 将数据写入XML或YAML文件,可采用以下步骤: 1.创建FileStorage对象.可以调用构造 ...

  9. Proxy 代理

    意图 为其他对象提供一种代理以控制对这个对象的访问 动机 对一个对象进行访问控制的原因是为了只有在我们确实需要这个对象时才对它进行创建和初始化 典型例子:智能指针的实现,通过引用计数来决定“=” 复制 ...

  10. GTK, GTK+, Qt, KDE, GNOME, Unity的区别与联系

    GTK,GTK+, Qt是图形界面开发库(GUI Toolkit),用户可以使用这些开发库编写GUI应用,其中GTK+是GTK的升级版. KDE,GNOME,Unity是linux下的桌面环境(Des ...