博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NUC1474 Ants【水题】
阅读量:6885 次
发布时间:2019-06-27

本文共 1996 字,大约阅读时间需要 6 分钟。

时间限制: 1000ms 内存限制: 65535KB

通过次数: 1总提交次数: 1

问题描述
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) 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.
输出描述
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.
样例输入
210 32 6 7214 711 12 7 13 176 23 191
样例输出
4 838 207
来源
Waterloo local 2004.09.19

问题分析:(略)

这个问题和《》是同一个问题,代码直接用就AC了。

程序说明:参见参考链接。

参考链接:

题记:程序做多了,不定哪天遇见似曾相识的。

AC的C++程序如下:

/* POJ1852 UVa10714 Ants */#include 
#include
using namespace std;int main(){ int t, l, n, pos, minans, maxans; scanf("%d", &t);; while(t--) { minans = 0; maxans = 0; scanf("%d%d", &l, &n); for(int i=1; i<=n; i++) { scanf("%d", &pos); minans = max(minans, min(pos, l - pos)); maxans = max(maxans, max(pos, l - pos)); } printf("%d %d\n", minans, maxans); } return 0;}

转载于:https://www.cnblogs.com/tigerisland/p/7563668.html

你可能感兴趣的文章
php中转义html标签
查看>>
jQuery.extend 函数详解
查看>>
The Nature of Lisp
查看>>
chineking / WeiboCrawler / wiki / Home — Bitbucket
查看>>
Java用native2ascii命令做unicode编码转换
查看>>
POST jpeg upload with AFNetworking
查看>>
wow 我的书单
查看>>
文件上传+截图+预览升级版-我们到底能走多远系列(23)
查看>>
C++ ORM - fg100emil的专栏 - 博客频道 - CSDN.NET
查看>>
html5之Canvas绘图工具基础介绍
查看>>
CSS:当鼠标移动到表格的某一行时改变其背景颜色
查看>>
在OEL5上安装配置Oracle Gird Control 10.2.0.5
查看>>
EXIT_SUCCESS_百度百科
查看>>
[转]C# 4.0 新特性
查看>>
HDU-4536 XCOM Enemy Unknown 枚举
查看>>
HDU 湫秋系列故事——安排座位 组和DP
查看>>
该不该让Google收录WordPress的目录页和标签页?
查看>>
Hypertable 0.9.7.3 发布,分布式数据库
查看>>
【leetcode】Best Time to Buy and Sell Stock
查看>>
JS判断浏览器类型
查看>>