题意:有n个数,现在要把他们拆分成两个集合,假设S为集合,有如下定义: f ( S ) = { m i n ( x ⊗ y ) ∣ x , y ∈ S a n d x ≠ y } f(S)=\{min(x\otimes y)|x,y\in S \ and\ x\neq y \} f(S)={ min(x⊗y)∣x,y∈S and x=y}将n个数拆分为两个集合A,B,要求最大化 m i n ( f ( A ) , f ( B ) ) min(f(A),f(B)\ ) min(f(A),f(B) ),并输出划分集合的方案,如果有多种,则输出任意一个
思路:
最小异或生成树。易发现若存在3个及以上相同的数,则无论如何划分,答案均为0.所以我们只需要考虑3个以下的数的情况。首先将所有数排序后,记录原本id再插入到最小异或生成树里面,那么考虑对答案有贡献的子树,分为以下几种情况。
- 子树的数的个数小于等于2,那么对于这种情况我们只需要将其分别放入不同的集合即可
- 子树的数的个数等于3,因为我们特判了存在3个及以上相同的数的可能,所以不存在一个叶子节点的数的可能为3的。所以我们只需要考虑子树的数的个数为1,2这种情况,这种情况下,我们只需要暴力枚举一下,找到使答案最大的分配方案并更新即可
- 子树的个数等于4,这种情况下可以递归为①0,4 ②1,3 ③2,2三种情况,对于①我们只需要接着递归即可,对于②便转化为2的情况。对于③,我们也需要暴力枚举一下,找到使答案最大的分配方案并更新即可
- 子树大于等于5,我们向下递归即可,最终都会变为1,2,3的情况。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pp;
const ll INF=1e17;
const int Maxn=2e7+10;
const int maxn =3e7+10;
const int mod= 1e9+7;
const int Mod = 1e6+7;
const int N = 1e5+10;
ll a[N];
int Isw[N];
ll mine;
struct qwq{
int id;
ll v;
bool operator<(const qwq& t){
return v<t.v;
}
bool operator==(const qwq&t){
return v==t.v;
}
};
qwq pop[</