这个题目还是比较简单的。
只需要先随便分一分,然后发现不满足条件就随便把两组随机的两个元素交换一下就可以了。
好像没有特别好的正确性证明?
#include <bits/stdc++.h>
using namespace std;
std::mt19937 mt_rand(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 233;
struct mono
{
int x, id;
bool operator<(const mono &rhs) const
{
return x > rhs.x;
}
} w1[N], w2[N], w3[N], w[N];
int tong[N];
signed main()
{
int k;
cin >> k;
uniform_int_distribution<int> rnd(1, k);
for (int i = 1; i <= 3 * k; i++)
cin >> w[i].x, w[i].id = i;
sort(w + 1, w + 3 * k + 1);
for (int i = 1; i <= k; i++)
w1[i] = w[i];
for (int i = 1; i <= k; i++)
w2[i] = w[i + k];
for (int i = 1; i <= k; i++)
w3[i] = w[i + k + k];
int s1 = 0, s2 = 0;
for (int i = 1; i <= k; i++)
s1 += w1[i].x;
for (int i = 1; i <= k; i++)
s2 += w2[i].x;
while (s1 <= k * 500 || s2 <= k * 500)
{
int r1 = rnd(mt_rand), r2 = rnd(mt_rand);
s1 -= w1[r1].x, s2 -= w2[r2].x;
swap(w1[r1], w2[r2]);
s1 += w1[r1].x, s2 += w2[r2].x;
}
for (int i = 1; i <= k; i++)
cout << w1[i].id << '\n';
for (int i = 1; i <= k; i++)
cout << w2[i].id << '\n';
for (int i = 1; i <= k; i++)
cout << w3[i].id << '\n';
return 0;
}