ACM:R: Optimal Parking
来源:互联网 发布:compareto方法比较数组 编辑:程序博客网 时间:2024/06/07 07:18
ACM:R: Optimal Parking
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
2424 13 89 3767 30 41 14 39 42
Sample Output
15270
注:不管在哪里停车,都需要把商店转一遍,并且再回到车中,即最大位置商店到最小位置商店距离的两倍。
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <cmath>#include <algorithm>#include <string>using namespace std;#define N 22int store[N];int cmp(const void *a,const void *b){return (*(int *)a-*(int *)b);}int main(){int T,n;cin>>T;
while(T--){
cin>>n;
for(int i=0;i<n;i++){
cin>>store[i];
}
qsort(store,n,sizeof(store[0]),cmp);cout<<store[n-1]*2-store[0]*2<<endl;}
return 0;}
- ACM:R: Optimal Parking
- 北大ACM poj3632 Optimal Parking
- 杭电 HDU ACM 1673 Optimal Parking
- Optimal Parking
- Optimal Parking
- Optimal Parking
- Optimal Parking
- POJ 3632 Optimal Parking
- poj3632 Optimal Parking!
- 1433. Optimal Parking
- poj 3632 Optimal Parking
- hdu 1673 Optimal Parking
- HDU1673:Optimal Parking
- hdu 1673 Optimal Parking
- HDU1673 Optimal Parking
- hdu1673 Optimal Parking
- 比赛 C - Optimal Parking
- Optimal Parking 1673
- doFilter如何使用
- 织梦仿站视频教程
- 【重点】React.Component用法
- Maven的安装和配置
- 一个全是bug的项目,调错详解
- ACM:R: Optimal Parking
- 商品展示
- STM32的GPIO有几种输出模式及其说明
- 欢迎使用CSDN-markdown编辑器
- 洛谷 P2024 食物链 【并查集+完美解释】
- 寻找最小的K个数
- webService实用性文章
- 山东省第八届ACM省赛 Problem.H triangle
- abstract抽象类和抽象方法