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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

BZOJ4245 [ONTAK2015]OR-XOR 【贪心】

發(fā)布時間:2024/4/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ4245 [ONTAK2015]OR-XOR 【贪心】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接

BZOJ4245

題解

套路①
位運(yùn)算當(dāng)然要分位討論,高位優(yōu)先
考慮在\(or\)下,如果該位為\(0\),則每一位都為\(0\)

套路②
我們選m段異或和,轉(zhuǎn)化為\(m\)個前綴和的點(diǎn),且其中有一個是\(n\)

容易發(fā)現(xiàn),該位結(jié)果要為0,則選取的前綴和該位都為\(0\)
所以貪心查找所有該位為\(0\)的,首先第\(n\)個前綴和一定要為\(0\),如果其它滿足有至少\(m - 1\)個,那么該位答案為\(0\),剩余為\(1\)的打上標(biāo)記不能選
如果不夠,那這一位就沒辦法了,直接放棄

#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<map> #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt) #define REP(i,n) for (int i = 1; i <= (n); i++) #define mp(a,b) make_pair<int,int>(a,b) #define cls(s) memset(s,0,sizeof(s)) #define cp pair<int,int> #define LL long long int using namespace std; const int maxn = 500005,maxm = 100005,INF = 1000000000; inline LL read(){LL out = 0,flag = 1; char c = getchar();while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}return out * flag; } int n,m,tag[maxn]; LL a[maxn],ans; int main(){n = read(); m = read();REP(i,n) a[i] = read() ^ a[i - 1];for (LL i = 1ll << 61; i; i >>= 1){if (a[n] & i){ans += i;continue;}int cnt = 1;for (int j = 1; j < n; j++)if (!tag[j] && !(a[j] & i)) cnt++;if (cnt >= m){for (int j = 1; j < n; j++)if (!tag[j] && (a[j] & i))tag[j] = true;}else ans += i;}printf("%lld\n",ans);return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/Mychael/p/9094057.html

總結(jié)

以上是生活随笔為你收集整理的BZOJ4245 [ONTAK2015]OR-XOR 【贪心】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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