博客
关于我
Codeforces Round #646 (Div. 2) C - Game On Leaves (树上博弈)
阅读量:724 次
发布时间:2019-03-21

本文共 1325 字,大约阅读时间需要 4 分钟。

题意:
给你一颗有n个节点的无根树,现在每次可以删除一个以叶子节点为端点的所有边并删除这个节点,现在指定一个节点x,谁先删到这个节点,谁就获胜(Ayush 先手 Ashish后手)。
叶子节点是指度小于等于1的节点

思路:

如果指定的节点本来是叶子节点,那么Ayush第一次就能直接拿到它,赢得比赛。这种情况下,Ayush肯定会赢。如果Ayush不能一举拿到,那么每个人都会尽量避免让指定节点的度降到1。也就是说,指定的节点一旦度为2,其他人就不会再主动删除与它相连的边,除非对方已经没有其他选择了。这让我想到这是一场拿数的博弈,谁先拿到只剩最后两个节点时谁就赢了。如果初始节点数n是偶数,Ayush一开始就能掌控节奏,最后让Ashish陷入孤立无援;反之,如果n是奇数,情况就有所不同,Ashish可能有机会反败为胜。

AC代码:

```cpp#include
#include
using namespace std;

int read() {char c = getchar();int x = 0, s = 1;while (c < '0' || c > '9') {if (c == '-') s = -1;c = getchar();}while (c >= '0' && c <= '9') {x = x * 10 + (c - '0');c = getchar();}return x * s;}

#define NewNode (TreeNode *)malloc(sizeof(TreeNode))#define Mem(a, b) memset(a, b, sizeof(a))

const int N = 1e5 + 5;const long long INFINF = 0x7f7f7f7f7f7f7f;const int INF = 0x3f3f3f3f;const double EPS = 1e-7;const unsigned long long mod = 998244353;const double II = acos(-1);const double PP = II * 1.0 / 180.0;

typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> pii;typedef pair<ll, ll> piil;

int main() {std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t;while (t--) {int n, x;cin >> n >> x;int ru[1050] = {0};for (int i = 0; i < n-1; ++i) {cin >> a >> b;ru[a]++, ru[b]++;}if (ru[x] <= 1) {cout << "Ayush\n";} else if (n % 2 == 0) {cout << "Ayush\n";} else {cout << "Ashish\n";}}}

转载地址:http://ynirz.baihongyu.com/

你可能感兴趣的文章
nio 中channel和buffer的基本使用
查看>>
NIO基于UDP协议的网络编程
查看>>
NISP一级,NISP二级报考说明,零基础入门到精通,收藏这篇就够了
查看>>
Nitrux 3.8 发布!性能全面提升,带来非凡体验
查看>>
NI笔试——大数加法
查看>>
NLog 自定义字段 写入 oracle
查看>>
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
NLP 项目:维基百科文章爬虫和分类【01】 - 语料库阅读器
查看>>
NLP_什么是统计语言模型_条件概率的链式法则_n元统计语言模型_马尔科夫链_数据稀疏(出现了词库中没有的词)_统计语言模型的平滑策略---人工智能工作笔记0035
查看>>
NLP学习笔记:使用 Python 进行NLTK
查看>>
NLP问答系统:使用 Deepset SQUAD 和 SQuAD v2 度量评估
查看>>
NLP:使用 SciKit Learn 的文本矢量化方法
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>