0526 POJ#1852&G2n J-Ants
来源:互联网 发布:行尸走肉第八季 知乎 编辑:程序博客网 时间:2024/05/22 06:42
摘要:
问题等效转换。
原题目链接:POJ - 1852
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) 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来源: https://cn.vjudge.net/problem/description/31057?1496011335000
题目认识:
测试数据,观察其结果特征。
注意:
如果能想出碰后的等效情况就好弄了
日期:
2017 5 26
代码:
#include <cstdio>
#include <algorithm>
#include <cmath>
#define MAX 101
int len,n;
double center;
int ans_max_x,ans_min_x;
int x;
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%d%d",&len,&n);
center=len/2;
ans_max_x=len/2,ans_min_x=0;
for(int i=0;i<n;i++){
scanf("%d",&x);
if(abs(x-center)>abs(ans_max_x-center))
ans_max_x=x;//far to center
if(abs(x-center)<abs(ans_min_x-center))
ans_min_x=x;//near to center
}
printf("%d %d\n",ans_min_x<len-ans_min_x?ans_min_x:len-ans_min_x,
ans_max_x < len-ans_max_x ? len-ans_max_x:ans_max_x );
}
return 0;
}
阅读全文
0 0
- 0526 POJ#1852&G2n J-Ants
- 0526 POJ#1088&G2n#C-滑雪
- poj 1852 Ants
- POJ 1852 Ants
- poj 1852Ants
- POJ 1852 Ants 蚂蚁
- POJ 1852 Ants
- POJ 1852 Ants
- POJ-1852-Ants
- POJ 1852 Ants
- [ACM] POJ 1852 Ants
- POJ 1852 Ants
- POJ 1852 Ants 模拟
- POJ 1852 ANTS
- poj 1852 ants
- POJ 1852 Ants
- POJ 1852 Ants
- POJ 1852 Ants
- ViewPager简单介绍
- 串口通讯常识介绍
- IT转型之路(一) 迷茫、困惑
- 第1章 那群“不可一世又招人喜欢的家伙”的崛起
- 判定某一年是否为闰年
- 0526 POJ#1852&G2n J-Ants
- 获取子集、转换元素,遍历、is().end()
- 阿里云centos安装mysql server
- Android Parcel源码笔记
- 自研php的仿java的ssh框架
- Dubbo入门使用
- 特性操作、获取、删除、增加等
- 大端法(big endian) 小端法(small endian)
- 制作Linux U盘启动(不只装机)盘(Ubuntu为例)