Ants
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 20047   Accepted: 8330

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

Source

 
【题解】
蚂蚁可以传过去。于是最大值就是每只蚂蚁向远的那一段走,最小值
就是每只蚂蚁向近的那一段走。每只蚂蚁的值取最大
 #include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a)) const int MAXN = + ;
const int INF = 0x3f3f3f3f; inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
} int t,n,l,num,ma,mi; int main()
{
read(t);
for(;t;--t)
{
read(l);read(n);
mi = ma = ;
for(register int i = ;i <= n;++ i)
{
read(num);
mi = max(mi, min(num, l - num));
ma = max(ma, max(num, l - num));
}
printf("%d %d\n", mi, ma);
}
return ;
}

POJ4852

 
 

POJ4852 Ants的更多相关文章

  1. 使用ANTS Performance Profiler&ANTS Memory Profiler工具分析IIS进程内存和CPU占用过高问题

    一.前言 最近一段时间,网站经常出现两个问题: 1.内存占用率一点点增高,直到将服务器内存占满. 2.访问某个页面时,页面响应过慢,CPU居高不下. 初步判断内存一点点增多可能是因为有未释放的资源一直 ...

  2. poj1852 Ants ——想法题、水题

    求最短时间和最长时间. 当两个蚂蚁相遇的时候,可以看做两个蚂蚁穿过,对结果没有影响.O(N)的复杂度 c++版: #include <cstdio> #define min(a, b) ( ...

  3. Uva10881 Piotr's Ants

    蚂蚁相撞会各自回头.←可以等效成对穿而过,这样移动距离就很好算了. 末状态蚂蚁的顺序和初状态其实是相同的. 那么剩下的就是记录每只蚂蚁的标号,模拟即可. /*by SilverN*/ #include ...

  4. [ACM_模拟] UVA 10881 Piotr's Ants[蚂蚁移动 数组映射 排序技巧]

    "One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one ...

  5. .NET性能调优之一:ANTS Performance Profiler的使用

    .NET性能调优系列文章 系列文章索引 .NET性能调优之一:ANTS Performance Profiler的使用 .NET性能调优之二:使用Visual Studio进行代码度量 .NET性能调 ...

  6. [CareerCup] 7.2 Ants on Polygon 多边形上的蚂蚁

    7.2 There are three ants on different vertices of a triangle. What is the probability of collision ( ...

  7. Uva---10881 Piotr's Ants(蚂蚁)

    Problem DPiotr's AntsTime Limit: 2 seconds "One thing is for certain: there is no stopping them ...

  8. Educational Codeforces Round 7 E. Ants in Leaves 贪心

    E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connec ...

  9. Codeforces Round #188 (Div. 1) B. Ants 暴力

    B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...

随机推荐

  1. String类型_static成员_动态内存分配_拷贝构造函数_const关键字_友元函数与友元类

    1:String类型 #include <iostream> using namespace std; int main() { //初始化方法 string s1 = "hel ...

  2. git 命令行(三)-删除文件

    在Git中,删除也是一个修改操作,我们实战一下,有一个多余的文件:src/common/Util2.js 我们需要删除这个文件, 一般情况下,你通常直接在文件管理器中把没用的文件删了,或者用 rm命令 ...

  3. 深入浅出 Java Concurrency (27): 并发容器 part 12 线程安全的List/Set[转]

    本小节是<并发容器>的最后一部分,这一个小节描述的是针对List/Set接口的一个线程版本. 在<并发队列与Queue简介>中介绍了并发容器的一个概括,主要描述的是Queue的 ...

  4. type 命令

    type 显示属于那种类型

  5. vue生成条形码/二维码/带logo二维码

    条形码:https://blog.csdn.net/dakache11/article/details/83749410 //安装 cnpm install @xkeshi/vue-barcode / ...

  6. leetcode 376Wiggle Subsequence

    用dp解 1)up定义为nums[i-1] < nums[i] down nums[i-1] > nums[i] 两个dp数组, up[i],记录包含nums[i]且nums[i-1] & ...

  7. jaxFileUpload插件异步上传图片

    第一步:引入jquery文件和jaxFileUpload文件 文件位置:https://pan.baidu.com/s/1jHEyIyy 第二步,前端: <div class="for ...

  8. JS创建和存储 cookie的一些方法

    在js中cookie的操作与存储及清除cookie都与时间有关,我们只要把cookie过期时间进行有效的设置我们就可以控制它的存储了,下面我来给大家总结一下js中cookie的一些使用技巧 创建和存储 ...

  9. python 日记 day1

    1.python2 与 python3 的区别:   a. python2 源码不标准,混乱,重复代码太多.默认方式是ascii码,解决方式:#-*- encoding:utf-8 -*-   b. ...

  10. oauth2使用心得-----基本概念以及认证服务器搭建

    应用场景 我们假设你有一个“云笔记”产品,并提供了“云笔记服务”和“云相册服务”,此时用户需要在不同的设备(PC.Android.iPhone.TV.Watch)上去访问这些“资源”(笔记,图片) 那 ...