NC223617. ARetribution!
描述
输入描述
Input starts with a line containing three positive integers: n m p (1 ≤ n ≤ m, p ≤ 1 000), representing the number of judges, tar repositories and feather storehouses, respectively. Following this are n lines, each containing two integers x y (|x|, |y| ≤ 10 000) specifying the locations of the n judges, starting with judge1. This is followed by m similar lines specifying the locations of the tar repositories (starting with repository 1) and p lines specifying the locations of the feather storehouses (starting with storehouse 1).
输出描述
Output the the sum of all distances between judges and their assigned tar repositories and feather storehouses, using the greedy method described above. Your answer should have an absolute or relative error of at most 10−6 .
示例1
输入:
2 2 2 1 0 2 0 0 0 3 0 1 1 2 1
输出:
4.0000000000
C++ 解法, 执行用时: 163ms, 内存消耗: 16536K, 提交时间: 2022-01-23 08:23:30
#include<bits/stdc++.h> using namespace std; int n[3], x[3][1234], y[3][1234]; double ans; #define sq(a) (a)*1LL*(a) void solve(int t) { vector<long long>vt, vs(1234), vc(1234); for(int i = 0; i < n[0]; i++) for(int j = 0; j < n[t]; j++) vt.push_back(sq(x[0][i]-x[t][j]) + sq(y[0][i]-y[t][j])<<32 | i<<16 | j); sort(vt.begin(), vt.end()); for(auto r : vt) { int s = r >> 16 & 65535, c = r & 65535; if(!vs[s] && !vc[c]) vs[s] = vc[c] = 1, ans += sqrt(r>>32); } } int main() { cin >> n[0] >> n[1] >> n[2]; for(int j = 0; j < 3; j++) for(int i = 0; i < n[j]; i++) cin >> x[j][i] >> y[j][i]; solve(1); solve(2); printf("%.10f", ans); }