泸州建设厅官方网站,网站seo跟短视频,免费空间访客领取网站,视频网站程序模板正题 ybtoj Trie-2 题目大意
给你n个数#xff0c;选择2个#xff0c;使其异或值最大 解题思路
对于每个数的二进制建立Trie#xff0c;然后每个数在Trie中搜索#xff0c;每次尽量走不同方向 代码
#includecstdio
#includecstring
#includeiostrea…正题 ybtoj Trie-2 题目大意
给你n个数选择2个使其异或值最大 解题思路
对于每个数的二进制建立Trie然后每个数在Trie中搜索每次尽量走不同方向 代码
#includecstdio
#includecstring
#includeiostream
#includealgorithm
#define ll long long
#define N 100100
using namespace std;
int n, x, w, ans, to[N*32][2];
void insert(int x)
{int now 0, y;for (int i 30; i 0; --i){y (xi)1;if (!to[now][y]) to[now][y] w;now to[now][y];}return;
}
int ask(int x)
{int ans 0, now 0, y 0;for (int i 30; i 0; --i){y (xi)1^1;//走不同方向if (to[now][y]) ans 1i;else y ^ 1;now to[now][y];}return ans;
}
int main()
{scanf(%d, n);for (int i 1; i n; i){scanf(%d,x);ans max(ans, ask(x));insert(x);}printf(%d, ans);return 0;
}