最多时间就是每仅仅蚂蚁选择最久的爬行方式

最少时间就是每仅仅蚂蚁选择最快地爬行方式

#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

SubmitStatus

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

Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Problem Solving Paradigms :: Greedy ::Non
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的更多相关文章

  1. UVA 10714 Ants 蚂蚁 贪心+模拟 水题

    题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...

  2. uva 10714 Ants(贪心)

    题目连接:10714 - Ants 题目大意:一根棍子上有n只蚂蚁, 这些蚂蚁开始可以任意朝着一个方向移动一直走,向左或是向右,并且移动速度是相同的,但是一旦蚂蚁碰到迎面走来的另一只蚂蚁,那么这两只蚂 ...

  3. UVA 1411 - Ants(二分图完美匹配)

    UVA 1411 - Ants 题目链接 题意:给定一些黑点白点,要求一个黑点连接一个白点,而且全部线段都不相交 思路:二分图完美匹配,权值存负的欧几里得距离,这种话,相交肯定比不相交权值小,所以做一 ...

  4. uva 1411 Ants (权值和最小的完美匹配---KM算法)

    uva 1411 Ants Description Young naturalist Bill studies ants in school. His ants feed on plant-louse ...

  5. poj 3565 uva 1411 Ants KM算法求最小权

    由于涉及到实数,一定,一定不能直接等于,一定,一定加一个误差<0.00001,坑死了…… 有两种事物,不难想到用二分图.这里涉及到一个有趣的问题,这个二分图的完美匹配的最小权值和就是答案.为啥呢 ...

  6. uva 1411 Ants

    题意: 一个平面上有n个黑色的点,n个白色的点,要求黑色的点与白色点之间一一配对,且线段之间不相交. 思路: 线段不相交并不好处理,想了很久想不出,所以看了蓝书的讲解. 一个很明显的结论是,不相交的线 ...

  7. 【uva 1411 Ants蚂蚁们】

    题目大意: ·给你一个n,表示输入n个白点和n个黑点(输入每一个点的坐标).现在需要将各个白点和各个黑点一一用线段连接起来,需要满足这些线段不能够相交. ·特色: 我们如何保证线段间不相交. ·分析: ...

  8. UVa 1411 Ants(分治)

    https://vjudge.net/problem/UVA-1411 题意:n只蚂蚁和n颗苹果树,一一配对并且不能交叉. 思路:这就是巨人与鬼的问题.用分治法就行了. #include<ios ...

  9. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. 网络编程——XML与JSON

    概述 如上篇博客点击打开链接介绍.互联网公司发布Web服务,于是开发者们就可以将其用到自己的应用中.Web服务的工作方式类似于浏览器,输入请求,按下回车,等待远程计算机响应.当响应返回时,浏览器会使用 ...

  2. shell命令批量杀死MySQL连接进程

    (1)将全部的MySQL连接进程杀掉 for i in `mysql -uroot -pzhangyun -Bse "show processlist" | grep -v &qu ...

  3. deinstall oracle 11g on linux

    deinstall oracle 11g on linux   From 11gR2, oracle provide us an deinstall tool. With that now we ca ...

  4. Knockout应用开发指南 第八章:简单应用举例(1)

    原文:Knockout应用开发指南 第八章:简单应用举例(1) 本章展示的4个例子主要是利用了Knockout的基本语法特性,让大家感受到使用Kncokout的快感. 1   Hello world ...

  5. Java流读写

    写: package com.wjy.write; import java.io.BufferedWriter; import java.io.FileOutputStream; import jav ...

  6. css实现背景渐变色效果

    webkit内核的浏览器,例如(chrome,safari等) background:-webkit-gradient(linear,0 0,0 100%,from(#000000),to(#ffff ...

  7. 建立qemu桥接的网络连接

    转载请注明出处谢谢:http://www.openext.org/2014/07/qemu-kvm-bridge-00     安装桥接工具:sudo apt-get install bridge-u ...

  8. php判断变量是否存在

    isset— 检测变量是否设置, isset() 只能用于变量,因为传递任何其它参数都将造成解析错误.若想检测常量是否已设置,可使用 defined() 函数. 如果已经使用 unset() 释放了一 ...

  9. POJ 1276  Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24132 Accepted: 8446 Descrip ...

  10. IT痴汉的工作现状13-吓唬电话

    那是一个普通的周末上午,稍微阴沉的天,使得暑气消退了好多.刚吃过早饭,我懒懒的浏览着CSDN论坛上有趣的问题和答案. 突然电话响起.是一个陌生的号码.我像往常一样接起电话,""您好 ...