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. 使用movable-view制作可拖拽的微信小程序弹出层效果。

    仿了潮汐睡眠小程序的代码.[如果有侵权联系删除 最近做的项目有个弹出层效果,类似音乐播放器那种.按照普通的做了一般感觉交互不是很优雅,设计妹子把潮汐睡眠的弹层给我看了看,感觉做的挺好,于是乘着有空仿照 ...

  2. OSG在VS2008下的配置安装

    一.准备工作 下载相关的工具软件: 1, 最新版的OSG库:OpenSceneGraph-2.8.2.zip. 2, 安装源代码所需要的工具:cmake-2.6.4-win32-x86.zip 3,  ...

  3. parameter–precharge, tRCD and tRAS

    以下描述来自wikipeida : https://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory 几点总结: (1) 每 ...

  4. 微信回调校验失败兼容php7

    今天在移动微信支付的代码的时候,发现校验失败,之前好好的,一点点打印了,顺着微信校验程序打印看结果,发现  $xml = $GLOBALS['HTTP_RAW_POST_DATA'];; 接收到的数据 ...

  5. ALS算法实现用户音乐打分预测

    很多人在决定是否看一部电影之前都会去豆瓣看下评分作为参考,看完电影也会给一个自己的分数.每个人对每个商品或者电影或是音乐都有一个心理的分数,这个分数标明用户是否对这个内容满意.作为内容的提供方,如果可 ...

  6. LL(1),LR(0),SLR(1),LALR(1),LR(1)对比与分析

    前言:考虑到这几种文法如果把具体内容讲下来肯定篇幅太长,而且繁多的符号对初学者肯定是极不友好的,而且我相信看这篇博客的人已经对这几个文法已经有所了解了,本篇博客的内容只是对 这几个文法做一下对比,加深 ...

  7. touch滑动事件---简单小案例

    html: <!--导航栏头部--><div class="type_nav"> <ul class="clearfix " v- ...

  8. java中通过jacob调用dts进行数据导入导出

    在一个项目中需要金蝶软件对接,但是业务服务器和财务服务器相隔很远(中间经过好几台服务器,有内网也有外网),从一个内网向另一个内网中传输时,需要外网辅助,因为不让原始数据受污染,使用了DTS数据同步到另 ...

  9. 机器学习之五 正则化的线性回归-岭回归与Lasso回归

    机器学习之五 正则化的线性回归-岭回归与Lasso回归 注:正则化是用来防止过拟合的方法.在最开始学习机器学习的课程时,只是觉得这个方法就像某种魔法一样非常神奇的改变了模型的参数.但是一直也无法对其基 ...

  10. Shell 语法之信号与作业

    Linux 使用信号与系统上运行的进程进行通信. Linux 编程中最常见的 Linux 系统信号 信号 值   描述 1  SIGHUP  挂起进程 2  SIGINT  中断进程 3  SIGQU ...