2017ACM暑期多校联合训练 - Team 6 1010 HDU 6105 Gameia (博弈)
Problem Description
Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes like this :
0. There is a tree with all node unpainted initial.
- Because Bob is the VIP player, so Bob has K chances to make a small change on the tree any time during the game if he wants, whether before or after Alice's action. These chances can be used together or separate, changes will happen in a flash. each change is defined as cut an edge on the tree.
- Then the game starts, Alice and Bob take turns to paint an unpainted node, Alice go first, and then Bob.
- In Alice's move, she can paint an unpainted node into white color.
- In Bob's move, he can paint an unpainted node into black color, and what's more, all the other nodes which connects with the node directly will be painted or repainted into black color too, even if they are white color before.
- When anybody can't make a move, the game stop, with all nodes painted of course. If they can find a node with white color, Alice win the game, otherwise Bob.
Given the tree initial, who will win the game if both players play optimally?
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with two integers N and K : the size of the tree and the max small changes that Bob can make.
The next line gives the information of the tree, nodes are marked from 1 to N, node 1 is the root, so the line contains N-1 numbers, the i-th of them give the farther node of the node i+1.
Limits
T≤100
1≤N≤500
0≤K≤500
1≤Pi≤i
Output
For each test case output one line denotes the answer.
If Alice can win, output "Alice" , otherwise "Bob".
Sample Input
2
2 1
1
3 1
1 2
Sample Output
Bob
Alice
题意:
Alice和Bob玩一个游戏,一开始有一颗有n个节点并且没有颜色的树,Bob和Alice分别对树上的节点进行染色,Alice每次将一个没有颜色的点涂成白色,Bob每次将一个没有颜色的点涂成黑色,并且可以将与涂上黑色的这个点直接相邻的点变为黑色,假如最后树被涂满之后还存在白色点,Alice赢,否则Bob赢。Bob还有一个特权,可以在任意时候,删除任意一条边,这样的特权可以使用k次。
分析:
首先当有一条长度大于等于3的链的时候,Alice一定可以获胜。可以找出来3 和 4 的时候这个结论是成立的。(3的时候先染中间那个点,4的时候先染最后一个点)当长度大于4的时候,Alice可以染倒数第二个点,那么Bob只能染最后一个点,否则他必输。这样就相当于将链的长度减小了2。那么接下去一定会变成3或4的链,Alice必胜。
实际上如果一个相连通的点集元素大于等于3的时候,Alice都是必胜的。因为如果是一棵树Alice可以用上述方式,每次染一个叶子节点的父节点,Bob只能染这个叶子结点。那么最后就会化成链或者只剩一个节点,那么她必胜。
对于一个节点连同它所有的子节点的个数如果是奇数的话,那么这样无论如何Alice都会赢,每次Alice先染白一个点,然后每次Bob涂的时候只有涂这个节点的子节点才能将这个节点再涂成黑色,这样他俩一轮下来只能涂两个,这样下来即使每个节点都是有两个子节点,最后被涂成白色的子节点个数最多为n/2-1个。
如果Bob的特权次数小于这个数的话,必然也是Alice赢。
如果为偶数的话,并且可以将这个树划分为所有都是只有两个点相连的话,Bob赢。
代码:
#include<stdio.h>
#include<vector>
using namespace std;
vector<int>vt[505];
int size[505];
int flag=0;
void dfs(int u)
{
int num=0;///奇数节点的个数
size[u]=1;
for(int i=0; i<vt[u].size(); i++)///递归所有的子节点
{
int to=vt[u][i];
dfs(to);
size[u]+=size[to];
if(size[to]%2==1)num++;///为奇数的节点(包括单独的叶子节点),Alice回赢
}
if(num>=2)flag=1;///这样的话也就相当于只有有两个节点的话,Bob才会赢
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=0; i<505; i++)vt[i].clear();
int n,k;
scanf("%d%d",&n,&k);
for(int i=2; i<=n; i++)
{
int f;
scanf("%d",&f);
vt[f].push_back(i);
}
flag=0;
if(n%2==1||n/2-1>k)///奇数个或者特权数不够用,必定Alice赢
printf("Alice\n");
else///节点个数为偶数个并且特权个数足够用
{
dfs(1);
if(flag==1)
printf("Alice\n");
else
printf("Bob\n");
}
}
}
2017ACM暑期多校联合训练 - Team 6 1010 HDU 6105 Gameia (博弈)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)
题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...
- 2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)
题目链接 Problem Description There is a nonnegative integer sequence a1...n of length n. HazelFan wants ...
- 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)
题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...
- 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)
题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...
- 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)
题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...
- 2017ACM暑期多校联合训练 - Team 7 1009 HDU 6128 Inverse of sum (数学计算)
题目链接 Problem Description There are n nonnegative integers a1-n which are less than p. HazelFan wants ...
随机推荐
- ubuntu通过apt-get方式搭建lnmp环境以及php扩展安装
v 一直是在用的lnmp的集成安装包搭建lnmp环境,因为工作需要需要安装ldap扩展,在网上怎么都找不到源码安装包,只能卸载掉原来的lnmp环境,用ubuntu的php5-ldap扩展, 在安装中遇 ...
- Win2019 + Oracle18c SQLPLUS 命令行出现乱码的解决
1. Win2019 中文版 安装了 Oracle数据库, dbca 建库时选择的 的字符集是 ZHS16GBK 然后发现使用sqlplus 时有乱码的现象如图示: 2. csdn 上面有一个博客有解 ...
- [CB] 中国超算前100 (联想40 曙光40 浪潮12 国防科大4 华为2 国家并行工程中心2 )
转帖 地址: https://www.cnbeta.com/articles/tech/779633.htm 榜单的前三名和去年相比没有任何变化,依然分别是部署在国家超级计算无锡中心的“神威·太湖之光 ...
- json_decode遇到的编码问题
初入csdn,就最近遇到的简单问题做一个功能解释; json_encode和json_decode只针对utf8字符有效,如果遇到其他编码比如gbk,需要进行转码然后解析: header(" ...
- 一张图看懂css的position里的relative和absolute的区别
position有以下属性:static.inherit.fixed.absolute.relative前三个好理解好区分:static:是默认状态,没有定位,元素出现在正常的流中(忽略 top, b ...
- 移动端开发-viewport
1.viewport viewport 即设备 屏幕上显示网页的区域.因为移动设备屏幕比较小,为了能让移动设备能够显示更多内容,默认设置的viewport 并不是屏幕真是像素点的宽度,一般为980px ...
- KMPnext数组自看
emm...无数次再看kmp了 因为一直没做相关的题..看了就忘看了就忘..emm.. next[i]表示去掉第i个元素后,自已的前缀和后缀完全匹配的最大长度 例 字符串 a b a b a b z ...
- UVA - 11997(巧妙的优先队列)
题意: 有k个整数数组,各包含k个元素,在每个数组中取一个元素加起来,可以得到kk个和,求这些和中最小的k个值 解析: 从简单的情况开始分析:经典方法,对原题没有思路,那么分析问题的简化版 这是对于两 ...
- StringUtils工具类说明
/***************************************为空判断***************************************/ //null 和 " ...
- Redis的Sorted Set有序集合命令
Sorted Set是Set的一个升级版本,它在Set的基础上增加了一个顺序属性,这一属性在添加修改元素的时候可以指定,每次指定后,zset会自动重新按新的值调整顺序.可以理解为有两列的mysql表, ...