Chatbox

Các bạn vui lòng dùng từ ngữ lịch sự và có văn hóa,sử dụng Tiếng Việt có dấu chuẩn. Chúc các bạn vui vẻ!
21/10/2013 21:10 # 1
vnttqb
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 5/130 (4%)
Kĩ năng: 39/80 (49%)
Ngày gia nhập: 21/03/2011
Bài gởi: 785
Được cảm ơn: 319
[code OLP ACM -2013] Problem C - Optimal Parking


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

Input specifications
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 ≤ x
i ≤ 99.

Output specifications
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

Output for sample input
152
70
 
 


======================================================================================================

Cuộc đời là một dòng sông. Ai không bơi thì chết. 
 

Name: Tien (Tory) TRAN
Email: TranTien29@gmail.com


 
21/10/2013 21:10 # 2
vnttqb
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 5/130 (4%)
Kĩ năng: 39/80 (49%)
Ngày gia nhập: 21/03/2011
Bài gởi: 785
Được cảm ơn: 319
Phản hồi: [code OLP ACM -2013] Problem C - Optimal Parking


#include"iostream"
#include"cstdio"
using namespace std;
int t,n;
int m[50];

void process(){
    cin>>n;
    int minm=111,maxm=-1;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        minm=min(minm,x);
        maxm=max(maxm,x);
    }
    cout<<2*(maxm-minm)<<endl;
}
int main(){
   //  freopen("optimalparking.txt","r",stdin);
    cin>>t;
    for(int i=0;i<t;i++)
        process();
    return 0;
}



======================================================================================================

Cuộc đời là một dòng sông. Ai không bơi thì chết. 
 

Name: Tien (Tory) TRAN
Email: TranTien29@gmail.com


 
Copyright© Đại học Duy Tân 2010 - 2024