答案:<pre class="brush:cpp;toolbar:false">#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <climits>
using namespace std;
vector<int> find_closest(const vector<int>& arr, int x) {
vector<int> res;
int n = arr.size();
if (n == 0) return res;
auto it = lower_bound(arr.begin(), arr.end(), x);
int pos = it - arr.begin();
if (pos == 0) {
res.push_back(arr[0]);
} else if (pos == n) {
res.push_back(arr.back());
} else {
int prev = arr[pos - 1];
int curr = arr[pos];
if (x - prev < curr - x) {
res.push_back(prev);
} else if (x - prev > curr - x) {
res.push_back(curr);
} else {
res.push_back(prev);
res.push_back(curr);
}
}
return res;
}
int main() {
int n1, n2, n3;
cin >> n1 >> n2 >> n3;
vector<int> S1(n1), S2(n2), S3(n3);
for (int i = 0; i < n1; ++i) cin >> S1[i];
for (int i = 0; i < n2; ++i) cin >> S2[i];
for (int i = 0; i < n3; ++i) cin >> S3[i];
sort(S1.begin(), S1.end());
sort(S2.begin(), S2.end());
sort(S3.begin(), S3.end());
vector<tuple<int, int, int>> candidates;
// Process S1 elements
for (int a : S1) {
auto b_list = find_closest(S2, a);
auto c_list = find_closest(S3, a);
for (int b : b_list) {
for (int c : c_list) {
candidates.emplace_back(a, b, c);
}
}
}
// Process S2 elements
for (int b : S2) {
auto a_list = find_closest(S1, b);
auto c_list = find_closest(S3, b);
for (int a : a_list) {
for (int c : c_list) {
candidates.emplace_back(a, b, c);
}
}
}
// Process S3 elements
for (int c : S3) {
auto a_list = find_closest(S1, c);
auto b_list = find_closest(S2, c);
for (int a : a_list) {
for (int b : b_list) {
candidates.emplace_back(a, b, c);
}
}
}
int min_range = INT_MAX;
for (const auto& t : candidates) {
int a = get<0>(t), b = get<1>(t), c = get<2>(t);
int current_min = min({a, b, c});
int current_max = max({a, b, c});
min_range = min(min_range, current_max - current_min);
}
vector<tuple<int, int, int>> min_candidates;
for (const auto& t : candidates) {
int a = get<0>(t), b = get<1>(t), c = get<2>(t);
int current_min = min({a, b, c});
int current_max = max({a, b, c});
if (current_max - current_min == min_range) {
min_candidates.push_back(t);
}
}
tuple<int, int, int> best = min_candidates[0];
for (const auto& t : min_candidates) {
if (t > best) {
best = t;
}
}
int a = get<0>(best), b = get<1>(best), c = get<2>(best);
int d = 2 * (max({a, b, c}) - min({a, b, c}));
cout << "LiXinLi(" << a << ", " << b << ", " << c << ") = " << d << endl;
return 0;
}</pre>
这道题暂未补解析。