POJ 1852:Ants
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 11754 | Accepted: 5167 |
Description
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
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
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 <iostream>
#include <algorithm>
#include <cmath>
using namespace std; int main()
{
int test;
cin>>test; while(test--)
{
int length,ant;
int min_val=-1,max_val=-1;
cin>>length>>ant; while(ant--)
{
int dis;
cin>>dis;
min_val=max(min_val,min(dis,length-dis));
max_val=max(max_val,max(dis,length-dis));
}
cout<<min_val<<" "<<max_val<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1852:Ants的更多相关文章
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...
- POJ 1852 Ants(贪心)
POJ 1852 Ants 题目大意 有n只蚂蚁在木棍上爬行,每只蚂蚁的速度都是每秒1单位长度,现在给你所有蚂蚁初始的位置(蚂蚁运动方向未定),蚂蚁相遇会掉头反向运动,让你求出所有蚂蚁都·掉下木棍的最 ...
- .NET性能调优之一:ANTS Performance Profiler的使用
.NET性能调优系列文章 系列文章索引 .NET性能调优之一:ANTS Performance Profiler的使用 .NET性能调优之二:使用Visual Studio进行代码度量 .NET性能调 ...
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- poj 1852&3684 题解
poj 1852 3684 这两题思路相似就放在一起. 1852 题意 一块长为L长度单位的板子(从0开始)上有很多只蚂蚁,给出它们的位置,它们的方向不确定,速度为每秒一长度单位,当两只蚂蚁相遇的时候 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- 弹性碰撞问题:Ants+Linear world
题目一:Ants 传送门 题目描述 输入 输出 样例 样例输入 样例输出 分析 一句话题意:有n只蚂蚁在木棍上爬行,每只蚂蚁的速度都是每秒1单位长度,现在给你所有蚂蚁初始的位置(蚂蚁运动方向未定),蚂 ...
- poj 1852 ants 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1852 题目描述 Description An army of ants walk on a horizontal pole of len ...
- Ants (POJ 1852)
题目描述: Description An army of ants walk on a horizontal pole of length l cm, each with a constant spe ...
随机推荐
- Electromagnetic
1. 电磁辐射 2. 电磁频谱 3. 可见光 4. 微波 5. 更多相关链接 1. 电磁辐射 https://en.wikipedia.org/wiki/Electromagnetic_radiati ...
- java中如何修改事务的隔离级别
事务的特性: 原子性(Atomicity)原子性是指事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不发生. (多条语句要么都成功,要么都失败.) 一致性(Consistency)事务前后 ...
- CSS3-多列(column-count等)
CSS3 多列属性 属性 描述 column-count 指定元素应该被分割的列数. column-fill 指定如何填充列 column-gap 指定列与列之间的间隙 column-rule 所有 ...
- LauUI 的学习
LayUI学习笔记 layer laydate layui 学习新技术方法:学习一个新技术,要去把它的文档通读一遍,不管你能不能读明白,就算你不明白也大概能知道它是怎么回事了,一回生二回熟,多读几遍, ...
- Ubuntu安装TTF字体
sudo mkdir /usr/share/fonts/ttf sudo cp ~/ttf/* /usr/share/fonts/ttf cd /usr/share/fonts/ttf sudo ch ...
- Py西游攻关之基础数据类型(六)-文件操作
Py西游攻关之基础数据类型 - Yuan先生 https://www.cnblogs.com/yuanchenqi/articles/5782764.html 九 文件操作 9.1 对文件操作流程 打 ...
- js加密(九)hr.bibibi md5
1. 寻找加密js: 2. 结果: 3. execjs调用js即可.
- 2016 黑客必备的Android应用都有哪些?
免责声明:本站所发布的此份清单仅供学习之用.我们不支持读者利用其中的任何工具进行任何不道德的恶意攻击行为. 根据业界的一系列评测以及亲身经验,我们整理出了这份最佳Android黑客应用清单.除了对应用 ...
- HBase查询速度慢原因排查
问题:通过HBase访问服务在HBase中查询 ASSET_NORMAL 表速度很慢 如下,查询一条数据需要2.970s时间: 如下,统计总条数需要14.675s时间: HBase访问服务部署了3个节 ...
- AngularJS1.X指令
<!DOCTYPE html> <html ng-app='myApp'> <head> <meta charset="utf-8"> ...