ACM 题目 求高人解答 (C C++)Problem Description JJ and WW go shopping together. You can assume the street as a straight line, while the shops are some points on the line. They park their car at the leftmost shop, visit all the shops from l

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 05:52:12
ACM题目求高人解答(CC++)ProblemDescriptionJJandWWgoshoppingtogether.Youcanassumethestreetasastraightline,whi

ACM 题目 求高人解答 (C C++)Problem Description JJ and WW go shopping together. You can assume the street as a straight line, while the shops are some points on the line. They park their car at the leftmost shop, visit all the shops from l
ACM 题目 求高人解答 (C C++)
Problem Description
JJ and WW go shopping together. You can assume the street as a straight line, while the shops are some points on the line. They park their car at the leftmost shop, visit all the shops from left to right, and go back to their car. Your task is to calculate the length of their route.

Input
The input consists of several test cases. The first line of input in each test case contains one integer N (0

ACM 题目 求高人解答 (C C++)Problem Description JJ and WW go shopping together. You can assume the street as a straight line, while the shops are some points on the line. They park their car at the leftmost shop, visit all the shops from l
///题目中说车停在最左边的商店,然后又要把所有的商店走完,并回来
///问的是最短距离,很显然是直接从左边走到右边再回来,那当然是取商店座标的最大
///值和最小值减一下乘以后就是答案了
#include
#include
int main()
{
int n;
int max_,min_;
int p;
while(scanf("%d",&n)!=EOF&&n>0)
{
n--;
scanf("%d",&max_);
min_=max_;
while(n--)
{
scanf("%d",&p);
if(pmax_)
{
max_=p;
}
}
printf("%d\n",(max_-min_)*2);
}
return 0;
}