[sicily]1433. Optimal Parking

1433. Optimal Parking

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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

简单计算题。求Michael 走的最小路程,简单思想就是停在最左边的店门口,走到最右边的店,然后回来。所以,只需求出最大最小值即可得。代码如下:


#include <iostream>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,tmp;
        cin>>n;
        int max = -1, min = 100;
        for(int i=0; i<n; i++)
        {
            cin>>tmp;
            if(tmp>max)max=tmp;
            if(tmp<min)min=tmp; 
        }
        cout<<((max-min)<<1)<<endl;
    }
    //system("pause");
    return 0;
}                                 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ICRA12_A Real-Time Motion Planner with Trajectory Optimization for Autonomous Vehicles.pdf IEEE_CASE2014_Design of Lane Keeping System Using Adaptive Model Predictive Control.pdf IEEE_CDC2012_Werling_AutomaticCollisionAvoidanceUsingModel-predictiveOnlineOptimization.pdf IEEE_ICRA2010_werling-optimal-trajectory-generation-for-dynamic-street-scenarios-in-a-frenet-frame.pdf IEEE_IROS2016_Snider_Automated Tactical Maneuver Discovery, Reasoning and Trajectory Planning for Automated Driving.pdf IEEE_ITSC2005_A new approach to lane guidance systems.pdf IEEE_ITSC2011_Algebraic nonlinear estimation and flatness-based lat lon conrol or automotive vehicles.pdf IEEE_ITSC2011_The H2-Optimal Preview Controller for a Shared Lateral Control.pdf IEEE_ITSC2013_Linear Model Predictive Control for Lane Keeping and Obstacle Avoidance on Low Curvature Roads.pdf IEEE_ITSC2016_Optimal Trajectory Planning for Autonomous Driving Integrating Logical Constraints_An MIQP Perspective.pdf IEEE_IV2010_Safety Verification of Autonomous Vehicles for Coordinated Evasive Maneuvers.pdf IEEE_IV2012_Learning Lane Change Trajectories From On-road Driving Data.pdf IEEE_IV2013_Higher_Order_Sliding_Mode_Control_for_Lateral_Dynamics_V0.pdf IEEE_IV2013_Robust Predictive Control for Semi-Autonomous Vehicles with an certain drivier model.pdf IEEE_IV2013_Snider_Focused Trajectory Planning for Autonomous On-Road Driving.pdf IEEE_TransHMS2017_Modeling, Identification, and Predictive Control of a Driver Steering Assistance System.pdf IEEE_TransSMC_2009Combined Automatic Lane-Keeping and Driver's Steering Through a 2-DOF Control Strategy.pdf" IEEE-TransIE2014_A real time energy optimal trajectory generation method for a servomotor system.pdf IEEE-TransITS2014_Ziegler_Making Bertha Drive-An Autonomous Journey on a Historic Route.pdf IJRR_Journal_2012_Werling_Optimal-trajectories-for-time-critical-street-scenarios-using-discretized-terminal-manifolds.pdf IROS_2015_Tunable and Stable Real-Time Trajectory Planning for Urban Autonomous Driving.pdf AI Model for Behaviour Arbitration.pdf Automatic_Steering_Methods_for_Autonomous_Automobile_Path_Tracking.pdf AVEC_2015_Lane Keeping Assistance with Learning-Based Driver Model and Model Predictive Control.pdf hoffmann_stanley_control07.pdf IAS_2014_On-Road Trajectory Planning for General Autonomous Driving with Enhanced Tunability.pdf ICINCO_2017_Time-Energy Optimal Trajectory Planning over a Fixed Path for a Wheel Mobile Robot.pdf ICIRA2012_On-Road Motion Planning for autonomous driving.pdf ICRA_2011_Energy-Optimal Velocity Profiles for Car-Like Robots.pdf

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值