UVa 11364 - Parking

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

題目網址
中文網址

Solution

只要停在最左和最右的店家之間,都要來回走一趟回到車子,距離都是 (max - min) * 2

Code

UVa 11364UVa 11364 - Parking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<cstdio>

int main()
{
int Case;
scanf("%d", &Case);
while (Case--)
{
int n, i, min = 100, max = 0, num;
scanf("%d", &n);

for (i = 0; i < n; i++)
{
scanf("%d", &num);
if (num > max)
max = num;
if (num < min)
min = num;
}

printf("%d\n", (max - min) * 2);
}
return 0;
}