HDU 3590 PP and QQ(反nim博弈,删边游戏)
生活随笔
收集整理的這篇文章主要介紹了
HDU 3590 PP and QQ(反nim博弈,删边游戏)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
PP and QQ
思路
刪邊游戲了解一下,其實(shí)就是個(gè)nim博弈吧,只是刪邊個(gè)數(shù)有特殊限制,
然后就是一個(gè)反nim博弈了。
刪邊定理:
-
遇到分叉口時(shí),它的子樹(shù)上的可操作的sg函數(shù)為所有子樹(shù)節(jié)點(diǎn)的sg函數(shù)的異或值,
然后這個(gè)異或值以一顆子樹(shù)的形式與這個(gè)點(diǎn)連為一棵樹(shù),然后不斷遞歸得到這一整棵樹(shù)的sg函數(shù)
反nim博弈:
必勝滿(mǎn)足sg=0,numvalue==1=evensg = 0, num_{value == 1} = evensg=0,numvalue==1?=even或者sg>0,numvalue>1>=1sg > 0, num_{value > 1} >= 1sg>0,numvalue>1?>=1,
代碼
/*Author : lifehappy */ #pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h>#define mp make_pair #define pb push_back #define endl '\n' #define mid (l + r >> 1) #define lson rt << 1, l, mid #define rson rt << 1 | 1, mid + 1, r #define ls rt << 1 #define rs rt << 1 | 1using namespace std;typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii;const double pi = acos(-1.0); const double eps = 1e-7; const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x; }vector<int> G[110];int dfs(int rt, int fa) {int ans = 1, now = 0;for(int i : G[rt]) {if(i == fa) continue;now ^= dfs(i, rt);}return ans + now; }int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int T;while(scanf("%d", &T) != EOF) {int ans = 0, num = 0;for(int cas = 1; cas <= T; cas++) {int n; scanf("%d", &n);for(int i = 1; i <= n; i++) {G[i].clear();}for(int i = 1; i < n; i++) {int x, y;scanf("%d %d", &x, &y);G[x].pb(y);G[y].pb(x);}int temp = dfs(1, 0) - 1;ans ^= temp;if(temp > 1) num++;}if((ans && num) || (!ans && !num)) puts("PP");else puts("QQ");}return 0; } 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的HDU 3590 PP and QQ(反nim博弈,删边游戏)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 微信微调研功能怎么才能实现
- 下一篇: 淘宝东西不想要想拒收怎么操作?