# Vito's Family 題目連結 [UVA 10040](https://onlinejudge.org/external/100/10041.pdf) ## 中文簡述 簡單來說就是你要從所有點中找出一個點到所有點的距離和為最小值。 ## solution: ``` #include <bits/stdc++.h> using namespace std; int main() { int kase; cin >> kase; while (kase--) { int n,mid; int ans=0; cin >> n; vector<int> nums(n); for (auto& i : nums) cin >> i; sort(nums.begin(), nums.end()); mid = nums[n/2]; for(auto& i :nums) ans+=abs(i-mid); cout<<ans<<endl; } return 0; } ``` ###### tags: `UVA` 回目錄 [學習筆記](/gIBZqAbWTCis7uOPp149gA)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up