GDUT_排位赛题解报告_第4场_E. Binary Tree

UG NX二次开发(C#)-VS2022配置NX二次开发模板不能正常显示的问题 随着VS2022的发布,使用VS2022进行UG NX二次开发的人员也会越来越多,但是由于VS2022和以前的VS版本采用代码结构不同,而UG NX的二次开发编程模板还没有适应于VS2022的模板配置,所以不能正常的创建一个完整的工程。本文采用曲线救国的方式来实现VS2022下的UG NX二次开发。如果有读者能很好的解决模板配置,不吝赐教。 阅读详情

题目:

In computer science, a binary tree is a rooted tree in which each node has at most two children. In this problem, let’s denote n as the number of nodes, l as the number of leaf nodes and h as the height of the tree (a tree consisting of only a root node has a height of 0).

Alice and Bob are playing a game with a binary tree. In this game, Alice and Bob have a binary tree, in which node 1 is the root. They take turns to perform operations on the tree, and Alice always takes the first turn. In each operation, the player taking the turn must choose a node p (any node including the root can be chosen), and remove the subtree rooted at p from the tree. Obviously, the remaining graph, if not empty, is still a binary tree. Then they continue to play with the resulting tree. To make the game more interesting, there is a restriction on which nodes can be chosen as p: the subtree rooted at p (the subtree to be removed) must be a perfect full binary tree. Note that a perfect full binary tree is a binary tree in which all interior (non-leaf) nodes have two children and all leaf nodes have the same depth. It can be easily shown that in a perfect full binary tree, the equation l=2h holds, so does the equation n=2h+1−1. In particular, a tree consisting of only a root node is also a perfect full binary tree. When a player is unable to perform a legal operation, the game ends and that player loses, which means the other player wins.

Three examples of perfect full binary trees.
Alice and Bob are both very smart and always play optimally. Can you determine who would win the game?

Input
The input contains multiple cases. The first line of the input contains a single positive integer T, the number of cases.

For each case, the first line of the input contains a single integer n (1≤n≤5000), the number of nodes in the binary tree. The following n−1 lines each contains two integers x,y (1≤x≤n,1≤y≤n), which denotes an edge between node x and y. It is guaranteed that the input graph is a binary tree rooted at node 1.

It’s guaranteed that the sum of n over all cases does not exceed 50000.

Output
For each case, print the string “Alice” in a single line if Alice would win the game, otherwise print the string “Bob”.

Example
inputCopy
1
5
1 2
1 3
3 4
3 5
outputCopy
Alice
Note
In the sample case, Alice removes the subtree rooted at node 3 in the first turn. Then Bob can only choose p=2, which leaves Alice with only the root node 1. Because a tree consisting of only a root node is a perfect full binary tree, Alice can remove the only remaining node and win the game.

题意就是给出一颗二叉树,然后两个人轮流移除完美二叉树,直到某一方拿走最后的点。

思路就是:每次拿走的完美二叉树,你会发现,点的数量是奇数,也就是两人轮流拿去一个奇数,这样的博弈,从奇偶性上面来直接判断谁胜谁负。

完整代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
const int INF = 0x3f3f3f3f;
//1.06e9大小
const int mod = 1e9+7;
typedef unsigned long long ULL;
typedef long long LL;
//鬼畜define
int main()
{
	int t;
	scanf("%d",&t);
	int n;
	while(t--)
	{
		scanf("%d",&n);
		int from,to;
		for(int time=0;time<n-1;time++){scanf("%d %d",&from,&to);}
		if(n%2==0)printf("Bob\n");
		else printf("Alice\n");
	}
}
电源完整性分析:PDN阻抗与去耦电容设计——目标阻抗计算与电容选型深度实战 摘要:随着嵌入式处理器主频突破 GHz、多核架构普及,电源完整性(Power Integrity, PI)已成为高速 PCB 设计中不可忽视的关键环节。本文从 PDN(电源分配网络)阻抗模型出发,系统讲解目标阻抗计算方法、去耦电容选型策略、反谐振抑制技术,并结合 STM32F4 核心板的完整设计实例,提供一套可落地的电源完整性工程实践方案。电源完整性设计是一项系统工程,需要从目标阻抗计算电容选型反谐振抑制PCB 布局目标阻抗是设计的起点,由电源电压、纹波要求和瞬态电流决定去耦电容。 阅读详情

相关推荐

基于Apache SeaTunnel构建CDC数据同步管道

Apache SeaTunnel是一个数据集成开发平台,其发展经历了几个重要阶段:ETL时代(90年代):面向结构化数据库的数据同步,用于构建数据仓库。MPP和分布式技术流行:使用技术如Hive进行数据仓库的构建。此阶段主要使用mapreduce程序进行数据搬运和转换。数据湖技术流行:重视数据集成,强调先同步数据至数据湖仓储,再进行业务面向的转换和设计。CDC,即变更数据捕获,是一种捕获数据库变更事件(如插入、更新、删除)的技术。

weixin_54625990的博客 2172

2021牛客暑期多校训练营4

F题 Just a joke 题目描述 Alice and Bob are playing a game. At the beginning, there is an undirected graph GGG with nnn nodes. Alice and Bob take turns to operate, Alice will play first. The player who can’t operate will lose the game. Each turn, the player shou

m0_51864047的博客 236

Audio2Face进阶玩法:结合LiveLink在UE5中实现MetaHuman全身动画+语音驱动(保姆级配置指南)

本文提供了一份详尽的保姆级教程,指导如何将NVIDIA Audio2Face与Unreal Engine 5的LiveLink功能结合,实现驱动MetaHuman数字人面部表情的同时,无缝融合身体动画。文章详细讲解了从环境准备、插件部署、基础面部驱动测试,到动画蓝图高级配置与多数据流融合的全流程,并分享了性能优化与问题排查的实战经验,旨在帮助创作者打造表情与肢体动作协调统一的生动数字人。

q9w8e7r6t5的博客 196

E. Binary Tree

GDUT 2020寒假训练 排位赛四 E 原题链接 E. Binary Tree 题目 In computer science, a binary tree is a rooted tree in which each node has at most two children. In this problem, let’s denote n as the number of nodes,...

xcy2001的博客 493

手把手教你用TBtools+MCScanX完成玉米基因家族共线性分析(附完整代码)

本文提供了一套完整的玉米基因家族共线性分析实战流程,详细讲解了如何从数据准备、格式处理开始,利用DIAMOND进行快速比对,再结合MCScanX进行核心共线性区块鉴定,最后通过TBtools实现从全基因组圈图到特定基因家族微共线性图的可视化。教程包含可直接运行的代码与常见问题解决方案,帮助研究者高效完成从命令行计算到图形化展示的全过程。

tech5的博客 591

香橙派R1 Plus LTS变身无线AP/客户端:手把手教你用RTL8811CU和MT7601U网卡刷OpenWRT

本文详细介绍了如何将香橙派R1 Plus LTS开发板通过RTL8811CU和MT7601U两款USB无线网卡刷入OpenWRT系统,实现无线AP热点发射与客户端接入的双重功能。从硬件选型、驱动安装到双网卡协同配置,提供完整的实战指南,帮助用户快速搭建稳定高效的无线网络解决方案。

weixin_30919429的博客 408

2020 GDUT Rating Contest IV (Div. 2) E. Binary Tree

来源 codeforces 2020 GDUT Rating Contest IV (Div. 2) CF链接 题目: outputstandard output In computer science, a binary tree is a rooted tree in which each node has at most two children. In this problem, let’...

qq_39581539的博客 200

【无人机基站】基于K-mean算法实现无人机基站部署附matlab代码

【无人机基站】基于K-mean算法实现无人机基站部署附matlab代码

天天酷科研的博客 242

树 练习题2

练习题

weixin_60833644的博客 2902

binning模式下和normal模式下相同曝光参数相同场景加权亮度差异消除方案优化(一)

摘要:针对ISP参数设置中浮点权重系数需转换为整数的问题,提出整数邻域搜索方案。该方法在浮点最优解附近(±1/±2)进行局部搜索,通过逐阶微调找到误差最小的整数权重组合,避免直接取整导致的误差反弹(误差从0.8%降至0.35%)。方案结合范围约束(1~15)和单调性约束(暗端递减、亮端递增),兼顾计算效率(单图耗时<10ms)与硬件兼容性,显著优于暴力搜索和简单取整,满足工程落地需求。

大熊 97

汽车UDS诊断详解及Vector相关工具链使用说明——总述

1.什么是诊断 车辆在运行过程中,不可避免地会发生一些故障,为了确保行车安全,我们要求车上的ECU能够实时监测部件的运行状态,一旦发现异常情况,能通过点亮报警灯等方式提示驾驶员。但是,点亮报警灯只能告诉驾驶员车辆发生了故障,最多只能定位到故障ECU,比如ABS报警灯亮说明ABS系统出现故障,但具体是什么部件发生故障并不能通过报警灯显示出来。这时就需要ECU在本地存储一个与故障相对应的故障代码,在进行维修的时候,可以通过车上的OBD接口连接诊断仪,把这个存储的故障代码读取出来,从而进一步定位到更加具体的故障部

weixin_42967006的博客 2万+

完美二叉树, 完全二叉树和完满二叉树

树在数据结构中占有非常重要的地位。本文从树的基本概念入手,给出完美(Perfect)二叉树,完全(Complete)二叉树和完满(Full)二叉树的区别。如果学习过二叉树,但是对这三种二叉树并没有深入的理解,或者完全被国产数据结构教科书所误导(只听说过满二叉树和完全二叉树)的朋友不妨花点时间耐着性子将本文仔细阅读N(>=1)遍。 1. 树(Tree)的基本概念 1.1 树的定义...

weixin_30527323的博客 1401

天爱验证码wasm验证码逆向

本文分析了某网站采用WASM加密技术的情况,发现其加密方式主要针对data和轨迹信息,整体加密逻辑变化不大。通过反混淆技术可以还原代码,并确认加密过程分为两步:先对原始参数逐个加密,再调用WASM模块进行最终加密。研究发现关键参数drives和ki都存储在WASM模块内,通过提取wasm_exec.js文件即可直接使用该加密功能。本文仅提供技术研究思路,强调严禁用于任何违法行为。

码王吴彦祖的博客 933

GDUT_排位赛题解报告_第3场_D. Race

Bessie is running a race of length K (1≤K≤109) meters. She starts running at a speed of 0 meters per second. In a given second, she can either increase her speed by 1 meter per second, keep it unchang...

DevourPower的博客 435

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

GDUT_排位赛题解报告_第2场_B. Snakes

题目: B. Snakes time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output According to legend, St. Patrick banished all of the snakes in Mooland over a tho...

DevourPower的博客 369

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

二叉树总结

分大概几个部分吧,定义(包括平衡、完全、满二叉树),基本性质、存储方式、遍历方法,树转成二叉树方法五个部分,最后是代码。 一、定义 wiki上定义:In computer science, a binary tree is a tree data structure in which each node has at most two child nodes, usually distingu

胜利者的经验并不复杂,那就是寻找人生的关键点,并在关键时刻竭尽全力 1784

GDUT_排位赛题解报告_第5场_C. 积木

题目: ChenJr已经两个月没有出门了,因此他已经无聊到开始用积木来玩搭房子游戏了。 ChenJr首先规定,对于搭建的每一栋房子,他只能选取长度为n的积木作为地基,之后他根据下述的规则进行搭建。 如果当前搭建的房子的最顶端的积木块的长度为k,那么ChenJr可以选择一个正整数i,(i∈[1,k2]),并在房子顶端放置一个长度为i的积木。或者ChenJr可以选择不再继续放置积木,代表当前的房子已经...

DevourPower的博客 354

B. 01 Game

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alica and Bob are playing a game. Initially they have a binary stringssconsisting of only characters0and1. Alice and Bob make altern...

无知的我 845

10-09训练赛week3-C3

A - Donut Shops CodeForces - 1373A There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this sho

Adrian099的博客 2795

B. 01 Game【模拟】

B.01GameAlica and Bob are playing a game. Initially they have a binary stringssconsisting of only characters0and1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. Dur...

qq_62079079的博客 366

东华大学2020年程序设计竞赛(同步赛)F.A Simple Game

东华大学2020年程序设计竞赛(同步赛)F.A Simple Game 题目链接 题目描述 Alice and Bob play a game.Initially they have n binary strings (a string which consists of zeroes and ones). They take alternating turns, and Alice is moving first. During each turn, the player has to choose se

旺崽的博客 2968

Educational Codeforces Round 90 (Rated for Div. 2) B. 01 Game(思维博弈)

01 Game 题目大意:(文末有原题) DA与NET玩游戏,给一个01串,他们只能删除 相邻的两个不同字符,DA先删,如果一个人没法删除,这个人就输了,判断最后谁会获胜; 思路: 因为是01串,所以能删多少次,与字符串的位置没有关系(只要既有1又有0,总会有相邻的01),所以只需判断有几个01对; 代码: #include <iostream> #include <cstring> using namespace std; int main() { int t;

Aurox_的博客 443

二叉树的遍历

1. what is binary tree a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child. 二叉树的第i层至多拥有2^i-1个节点; 满二叉树(Full ...

地山谦的博客 363

Easy Game(博弈dp,区间dp)

https://cn.vjudge.net/problem/LightOJ-1031 You are playing a two player game. Initially there areninteger numbers in an array and playerAandBget chance to take them alternatively. Each player c...

永夜莫明的博客 519

简单博弈问题

问题:Alice and Bob are playing a kind of special game on an N*M board (N rows, M columns). At the beginning, there are N*M coins in this board with one in each grid and every coin may be upward or downw...

weixin_30781775的博客 339

Sicily1798. Alice and Bob[策略问题]

策略问题,通过数学推理,完成解决。 基础的思维转换的问题。 Sicily

gc.collect() 1721

HDU4597:Play Game(记忆化)

Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from

ACM!荣耀之路! 2956
上一篇: GDUT_排位赛题解报告_第3场_B.Loan Repayment
下一篇: GDUT_排位赛题解报告_第4场_C. Defining Labels
DevourPower
博客等级 码龄7年 52粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值