Shopping
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Saya and Kudo 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.
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.
输入
The input consists of several test cases.
The first line of input in each test case contains one integer N (0<N<100001), represents the number of shops.
The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 2^30.
The last case is followed by a line containing one zero.
The first line of input in each test case contains one integer N (0<N<100001), represents the number of shops.
The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 2^30.
The last case is followed by a line containing one zero.
输出
For each test case, print the length of their shopping route.
示例输入
4 24 13 89 37 6 7 30 41 14 39 42 0
示例输出
152 70
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
while(~scanf("%d",&n) && n)
{
int MAX = -1;
int MIN = 0x3f3f3f3f;
for(int i=0; i<n; i++)
{
scanf("%d",&m);
MAX = max(MAX, m);
MIN = min(MIN, m);
}
printf("%d\n",(MAX-MIN)*2);
}
}

本文介绍了一个计算购物路径长度的问题,假设街道为一条直线,商店位于这条直线上,任务是计算从最左侧商店出发,访问所有商店后返回起点的总路程。文章提供了具体的输入输出示例及代码实现。

被折叠的 条评论
为什么被折叠?



