UVA - 10714 Ants
最多时间就是每仅仅蚂蚁选择最久的爬行方式
最少时间就是每仅仅蚂蚁选择最快地爬行方式
#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int a,b,i,T,len,n,t;
cin>>T;
while(T--)
{
cin>>len>>n;
a=b=0;
while(n--)
{
cin>>t;
a=max(a,min(len-t,t));
b=max(b,max(len-t,t));
}
cout<<a<<" "<<b<<endl;
}
return 0;
}
| Time Limit:3000MS | Memory Limit:Unknown | 64bit IO Format:%lld & %llu |
Description


Problem B: Ants
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.
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) andn, the number of ants residing on the pole. These two numbers are followed
byn 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.
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
Output for sample input
4 8
38 207
Piotr Rudnicki
Source
Classical, Usually Harder
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 4. Algorithm Design
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Problem Solving Paradigms ::Greedy
- Standard
Root :: Prominent Problemsetters :: Piotr Rudnicki
UVA - 10714 Ants的更多相关文章
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- uva 10714 Ants(贪心)
题目连接:10714 - Ants 题目大意:一根棍子上有n只蚂蚁, 这些蚂蚁开始可以任意朝着一个方向移动一直走,向左或是向右,并且移动速度是相同的,但是一旦蚂蚁碰到迎面走来的另一只蚂蚁,那么这两只蚂 ...
- UVA 1411 - Ants(二分图完美匹配)
UVA 1411 - Ants 题目链接 题意:给定一些黑点白点,要求一个黑点连接一个白点,而且全部线段都不相交 思路:二分图完美匹配,权值存负的欧几里得距离,这种话,相交肯定比不相交权值小,所以做一 ...
- uva 1411 Ants (权值和最小的完美匹配---KM算法)
uva 1411 Ants Description Young naturalist Bill studies ants in school. His ants feed on plant-louse ...
- poj 3565 uva 1411 Ants KM算法求最小权
由于涉及到实数,一定,一定不能直接等于,一定,一定加一个误差<0.00001,坑死了…… 有两种事物,不难想到用二分图.这里涉及到一个有趣的问题,这个二分图的完美匹配的最小权值和就是答案.为啥呢 ...
- uva 1411 Ants
题意: 一个平面上有n个黑色的点,n个白色的点,要求黑色的点与白色点之间一一配对,且线段之间不相交. 思路: 线段不相交并不好处理,想了很久想不出,所以看了蓝书的讲解. 一个很明显的结论是,不相交的线 ...
- 【uva 1411 Ants蚂蚁们】
题目大意: ·给你一个n,表示输入n个白点和n个黑点(输入每一个点的坐标).现在需要将各个白点和各个黑点一一用线段连接起来,需要满足这些线段不能够相交. ·特色: 我们如何保证线段间不相交. ·分析: ...
- UVa 1411 Ants(分治)
https://vjudge.net/problem/UVA-1411 题意:n只蚂蚁和n颗苹果树,一一配对并且不能交叉. 思路:这就是巨人与鬼的问题.用分治法就行了. #include<ios ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
随机推荐
- 网格最短路径算法(Dijkstra & Fast Marching)(转)
Dijkstra算法是计算图中节点之间最短路径的经典算法,网上关于Dijkstra算法原理介绍比较多,这里不再多讲.值得一提的是,当图中节点之间的权重都为1时,Dijkstra算法就变化为一般意义上的 ...
- Android---App Widget(一)
本文译自:http://developer.android.com/guide/topics/appwidgets/index.html App Widgets是一些较小的应用程序窗口,它们能够被嵌入 ...
- How to debug with IntelliJ IDEA + Grails 2.3.x (转)
问题: 最近访问grails.org,看到grails framework已经发展到2.3.x了,不免想尝尝鲜.下载了最新的grails-2.3.x之后,创建了一个新的grails app. 添加Bo ...
- A First Exploration Of SolrCloud
A First Exploration Of SolrCloud Update: this article was published in August 2012, before the very ...
- xpages的comboBox能够手动输入
在xpages使用的comboBox默认仅仅能选择.不能手动输入,怎么才干手动输入呢?经过查找资料和測试,最终能够了,请大家能够试试 假设试不行,能够再下载demo http://download.c ...
- 天嵌E9平台下进行USB Wifi模块RT3070驱动的移植
因为项目工作须要,要在天嵌E9平台下实现wifi的点对点,点对多点的传输. Wifi 模块芯片:雷凌3070芯片 嵌入式平台:E9(ARM) 交叉编译环境:arm-none-linux-gnueabi ...
- Codeforces Round#201(div1) D. Lucky Common Subsequence
题意:给定两个串,求出两个串的最长公共子序列,要求该公共子序列不包含virus串. 用dp+kmp实现 dp[i][j][k]表示以i结尾的字符串和以j结尾的字符串的公共子序列的长度(其中k表示该公共 ...
- Mysql 当安装完成后不执行 mysql 和 performance_schema 数据库
Mysql问题 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Mysql ...
- zigbee学习:示例程序SampleApp中通讯流程
zigbee学习:示例程序SampleApp中通讯流程 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 参考链接: http://wjf88223.bl ...
- [Cocos2d-x v3.x]浅谈容器Vector
转载请注明来自:star特530的CSDN博客 http://blog.csdn.net/start530/article/details/19170853 前两天有人问我说在3.0 beta2版本号 ...