【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e511
【解題想法】
- 不管停車在哪一個位置,想逛完所有想去的商店,一定要走最大座標與最小座標之間的距離的兩倍。
#include <iostream>
using namespace std;
int main() {
int T, n;
cin >> T;
for (int Case = 1; Case <= T; Case++) {
cin >> n;
int x, mn = 100, mx = 0;
for (int i = 0; i < n; i++){
cin >> x;
if (x > mx) mx = x;
if (x < mn) mn = x;
}
cout << (mx - mn) * 2 << "\n";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int T, n;
cin >> T;
while (T--){
cin >> n;
int x, mn = 100, mx = 0;
for (int i = 0; i < n; i++){
cin >> x;
if (x > mx) mx = x;
if (x < mn) mn = x;
}
cout << (mx - mn) * 2 << "\n";
}
return 0;
}