日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Trie UVALive 7192 Chip Factory (15长春J)

發(fā)布時(shí)間:2025/7/25 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Trie UVALive 7192 Chip Factory (15长春J) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

題目傳送門(mén)

題意:從n個(gè)數(shù)中選出不同的三個(gè)數(shù)a b c,使得(a+b)^c 最大

分析:先將所有數(shù)字按位插入到字典樹(shù)上,然后刪除兩個(gè)數(shù)字,貪心詢問(wèn)與剩下的數(shù)字最大異或值。?

/************************************************ * Author :Running_Time * Created Time :2015/11/1 14:58:49 * File Name :J.cpp************************************************/#include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std;#define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; struct Trie {int ch[N*30][2], sz;int cnt[N*30];void init(void) {sz = 1; ch[0][0] = ch[0][1] = 0;memset (cnt, 0, sizeof (cnt));}void insert(int x) {int u = 0;for (int c, i=30; i>=0; --i) {c = x & (1 << i) ? 1 : 0;if (!ch[u][c]) {ch[sz][0] = ch[sz][1] = 0;ch[u][c] = sz++;}u = ch[u][c];cnt[u]++;}}void remove(int x) {int u = 0;for (int c, i=30; i>=0; --i) {c = x & (1 << i) ? 1 : 0;u = ch[u][c];cnt[u]--;}}int query(int x) {int u = 0;for (int c, i=30; i>=0; --i) {c = x & (1 << i) ? 1 : 0;if (c == 1) {if (ch[u][0] && cnt[ch[u][0]]) u = ch[u][0];else u = ch[u][1], x ^= (1 << i);}else {if (ch[u][1] && cnt[ch[u][1]]) u = ch[u][1], x ^= (1 << i);else u = ch[u][0];}}return x;} }trie; int a[N];int main(void) {int T; scanf ("%d", &T);while (T--) {int n; scanf ("%d", &n);for (int i=1; i<=n; ++i) {scanf ("%d", &a[i]);}int ans = 0;trie.init ();for (int i=1; i<=n; ++i) {trie.insert (a[i]);}for (int i=1; i<=n; ++i) {trie.remove (a[i]);for (int j=i+1; j<=n; ++j) {trie.remove (a[j]);ans = max (ans, trie.query (a[i] + a[j]));trie.insert (a[j]);}trie.insert (a[i]);}printf ("%d\n", ans);}return 0; }

  

轉(zhuǎn)載于:https://www.cnblogs.com/Running-Time/p/4956062.html

總結(jié)

以上是生活随笔為你收集整理的Trie UVALive 7192 Chip Factory (15长春J)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。