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

数字信号处理实验:信号谱分析与FFT算法的应用 ​ (1)给定信号为 ,其中a为42,b为1。理论分析信号 的频率成分。 (2)分别采用采样频率为 , , , 对 进行采样,其中 , , , ,根据是否满足采样定理要求分析四种采样频率下频谱的分布,在满足采样定理情况下做频谱分析。 (3)任意生成两组有限长信号,对信号分别进行直接卷积和FFT算法求卷积,并分析圆周卷积与线性卷积的关系。 阅读详情

题目:

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");
	}
}
Open3D 计算点云的倒角距离(Chamfer Distance)【2025最新版】 ;Chamfer Distance距离可以计算生成点云数据与标签点云数据之间的平均最短点距离。Open3D可以直接用来计算点云的Chamfer Distance距离。博客长期更新,本文最近一次更新时间为:2025年2月18日。 阅读详情

相关推荐

物理机centos7系统重启后直接进入dracut

Warning: /dev/centos/root does not exist Warning: /dev/mapper/centos-root does not exist 在shell命令行执行以下: dracut:/# lvm vgscan dracut:/# lvm vgchange -ay dracut:/# exit 之后可以正常进入系统(测试正常)。 但是重启之后依然会进入dracut模式,永久解决如下: 查看kernel文件 [root@ecs ~]# ls -ltrh /boot

魏志标的博客 1万+

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

从CCD数据上报看wxHOOK的封号风险与规避

本文深入分析了微信CCD数据上报机制对wxHOOK的检测逻辑与封号风险,揭示了调试器路径暴露、非白名单DLL加载和内存校验失败等关键风险点。通过实战案例和规避方案,帮助开发者理解如何安全使用wxHOOK技术,避免封号风险,包括内存镜像欺骗、内核级隐蔽和硬件辅助方案等高级技巧。

weixin_27875131的博客 642

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

华为ITR流程实战指南:从设计到落地的全流程解析(附完整方案下载)

本文深度解析华为ITR流程从设计到落地的全流程实战指南。ITR不仅是高效处理客户问题的“救火”系统,更是驱动产品改进、预防问题的企业“免疫系统”。文章详细拆解了流程设计的四步走策略、三层技术支持体系的组织保障、以闭环改进为核心的考核激励,并探讨了如何借鉴其精髓,优化自身问题管理,实现从被动响应到主动服务的跨越。

y2z3a4b5c的博客 388

阿里云人工智能工程师ACA认证免费课程学习笔记

阿里云人工智能工程师ACA认证免费课程学习笔记

engchina的专栏 2019

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的博客 201

ADRV9009的学习历程(一)

** AD9361的同胞ADRV9009 ** 终于记录一下了 距离第一次想写博客记录自己学习的点点滴滴,大概已经过去有一年有余。一直都是停留在心有余而力不足的境界。 基本每次做项目遇到问题都会来CSDN寻求帮助,这里虽离庙堂较远,但高手云集。每每读来,思绪万千,次次膜拜。 趁这次又学习了一样新物件,就记录一下,望大神看见能赐教一下。 ADRV9009 最近有项目要用到ADRV9009这个芯片。就来学习一下。做过AD9361的都知道,ADI官方会给出这个芯片的参考手册、数据手册和驱动程序。当然我只是见过AD

weixin_42868560的博客 1万+

树 练习题2

练习题

weixin_60833644的博客 2904

基于Simulink的锂电池热模型与温控管理仿真

本文完成了基于Simulink的锂电池热模型与温控管理仿真,实现了:✅ 建立电-热耦合产热模型✅ 构建集总参数热网络✅ 设计基于迟滞的风扇启停控制✅ 验证在高倍率工况下的有效温控能力✅ 为实际电池热管理系统(BTMS)提供设计原型。

xiaoheshang_123的博客 153

学 Simulink—— 基于强化学习(DDPG)的电机无位置传感器控制仿真

Actor:输入状态s,输出θ̂_dot(即 ω̂),积分得 θ̂Critic:评估"估计角度与反电动势模型一致性"的 Q 值奖励函数不依赖真实 θ(无监督式自监督),只用iαβ预测残差。

amy_mhd的博客 22

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

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

weixin_30527323的博客 1401

ROS机器人未知环境自主探索功能包explore_lite最全源码详细解析(一)

本系列文章主要针对ROS机器人常使用的未知环境自主探索功能包explore_lite展开全源码的详细解析,并进行概括总结。 本系列文章共包含六篇文章,前五篇文章主要介绍explore_lite功能包中 explore.cpp、costmap_tools.h、frontier_search.cpp、costmap_client.cpp等源码实现文件中全部函数的详细介绍,第六篇文章进行概括总结,包含自主探索功能包explore_lite的简介,实现未知环境自主探索功能的原理及流程总结,效果演示,使用功能包

慕羽★的博客 3944

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的博客 436

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

二叉树总结

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

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

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

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

DevourPower的博客 355

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...

无知的我 848

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的博客 2798

东华大学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

旺崽的博客 2970

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

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

ocp 1Z0-051 1-22题解析

1. View the Exhibit andexamine the structure of the SALES, CUSTOMERS, PRODUCTS, and TIMES tables. The PROD_ID column isthe foreign key in the SALES table, which references the PRODUCTS table. Simil

Database、Code 9058

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!荣耀之路! 2958

简单博弈问题

问题: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

GDUT_排位赛题解报告_第4场_C. Defining Labels

题目: Microsoft Excel is a spreadsheet developed by Microsoft. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications. It has been a...

DevourPower的博客 423

Sicily1798. Alice and Bob[策略问题]

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

gc.collect() 1729
上一篇: 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、付费专栏及课程。

余额充值