码迷,mamicode.com
首页 > 其他好文 > 详细

杭电 HDU ACM 1673 Optimal Parking

时间:2015-04-07 10:03:56      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:acm   c++   杭电   算法   编程   

Optimal Parking

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1942    Accepted Submission(s): 1624


Problem Description
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.
 

Input
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
Output for each test case a line with the minimal distance Michael must walk given optimal parking.
 

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

Sample Output
152 70
 
醒来 继续AC这些无聊的玩意儿 ,争取一周内a掉水题,深入算法数据结构!
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,x;
	int ls[101];
	cin>>n;
	while(n--)
	{
		int sum=0;
		cin>>m;
	    for(int i=0;i<m;i++)
			cin>>ls[i];
		sort(ls,ls+m);
		cout<<2*(ls[m-1]-ls[0])<<endl;
	}
	return 0;
}


杭电 HDU ACM 1673 Optimal Parking

标签:acm   c++   杭电   算法   编程   

原文地址:http://blog.csdn.net/lsgqjh/article/details/44904605

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!