2017 Multi-University Training Contest - Team 6 HDU 6105 Gameia(博弈)
題目鏈接:
HDU 6105 Gameia
題目大意:
給一棵樹,
解題思路:
- 首先要知道, B的機會, 如果他要用,那麼可以視爲在最剛開始就用。
- 然後是博弈的問題, 比賽的時候學長在寫6103字符串那題, 我就在旁邊推這個博弈, 畫了幾個圖發現, 對於一條鏈來說, 只有長度爲2的時候B才必勝, 因爲鏈長度爲
1,3,4. A必勝,如果長度大於4, 那麼A一定可以通過染最邊上或者邊上的第二個使得這條鏈以−2,或者−3 的長度縮減, 最終變成長度爲3或4 , 這樣又變成了A必勝。 這裏不理解的可以自己畫一下, 因爲AB都絕對聰明, 而且A先手。
對於一棵樹來說, 也是如此, 並且在樹上A更佔優勢, 因爲有很多分支點。 所以我就想把這棵樹切成兩兩一段。 看需要次數是否超過k, 還要判斷存在切完之後是否存在單點的情況。(如果存在單點, A點一下必勝)。
代碼:
/**********************************************
*Author* :ZZZZone
*reated Time* : 2017/8/10 14:29:50
*ended Time* : 2017/8/10 14:41:02
*********************************************/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const int MaxN = 500;
int n, k, tot;
int all, pre[2 * MaxN + 5], last[MaxN + 5], other[2 * MaxN + 5];
bool ok, vis[MaxN + 5];
int ind[MaxN + 5];
void Build(int x, int y) {
pre[++all] = last[x];
last[x] = all;
other[all] = y;
}
void Dfs(int x, int fa) {
int ed = last[x];
int cnt = 0;
while(ed != -1) {
int dr = other[ed];
if(dr != fa) {
Dfs(dr, x);
if(ind[dr] > 0 || ind[x] > 0) tot++;
else ind[dr]++, ind[x]++;
}
ed = pre[ed];
}
}
int main()
{
int T;
scanf("%d", &T);
while(T--) {
all = -1; memset(last, -1, sizeof(last));
memset(vis, 0, sizeof(vis));
memset(ind, 0, sizeof(ind));
scanf("%d%d", &n, &k);
for(int i = 2; i <= n; i++) {
int x;
scanf("%d", &x);
Build(x, i); Build(i, x);
}
ok = 1; tot = 0;
Dfs(1, 0);
for(int i = 1; i <= n; i++) if(ind[i] == 0) ok = 0;
if(tot > k) ok = 0;
if(ok) printf("Bob\n");
else printf("Alice\n");
}
return 0;
}