首页 > ACM题库 > HDU-杭电 > HDU 1673 Optimal Parking[解题报告] C++
2013
12-21

HDU 1673 Optimal Parking[解题报告] C++

Optimal Parking

问题描述 :

When shopping on Long Street, Michael usually parks his car at some random location, and then walks to the stores he needs.
Can you help Michael choose a place to park which minimises the distance he needs to walk on his shopping round?
Long Street is a straight line, where all positions are integer.
You pay for parking in a specific slot, which is an integer position on Long Street. Michael does not want to pay for more than one parking though. He is very strong, and does not mind carrying all the bags around.

输入:

The first line of input gives the number of test cases, 1 <= t <= 100. There are two lines for each test case. The first gives the number of stores Michael wants to visit, 1 <= n <= 20, and the second gives their n integer positions on Long Street, 0 <= xi <= 99.

输出:

Output for each test case a line with the minimal distance Michael must walk given optimal parking.

样例输入:

2
4
24 13 89 37
6
7 30 41 14 39 42

样例输出:

152
70

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1673

题意:一条路上有n家商店,给出坐标。某人停车在某点后,要逛完所有商店回到车出。停车地点自选,求最少需要步行多远。

mark:唬人,其实就是最大值与最小值差的两倍。

代码:

# include <stdio.h>
 
 
 int main ()
 {
     int T, n, num ;
     int max, min ;
     scanf ("%d", &T) ;
     while (T--)
     {
         scanf ("%d", &n) ;
         max = -1, min = 1000 ;
         while (n--)
         {
             scanf ("%d", &num) ;
             if (num > max) max = num ;
             if (num < min) min = num ;
         }
         printf ("%d\n", (max-min)*2) ;
     }
     
     return 0 ;
 }

解题报告转自:http://www.cnblogs.com/lzsz1212/archive/2012/04/27/2472919.html


  1. 第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。