题目大意:

给定一棵n个结点的树

一开始黑方占据1号结点,白方占据n号结点

其他结点都没有颜色

每次黑方可以选择黑色结点临近的未染色结点,染成黑色

白方同理。

最后谁不能走谁输。

题解:

其实简单想想就可以想明白。

黑方肯定要往通往白方的最短路延伸,白方也是这样。

因为这样每次你可以最大化可行动次数。

所以先以1为根,dfs一遍,然后找到路径。

模拟一下走路径的过程,路径走光了就比谁的可行动次数多(有点像围棋的气的感觉),输出结果就可以了

#include <iostream>
#include <cstdio>
#include <deque>
#include <vector>
using namespace std;
const int maxn = 1e5 + ;
vector<int> G[maxn];
int deep[maxn], sz[maxn], f[maxn];
deque<int> Q;
void dfs(int x, int fa, int d){
deep[x] = d;
sz[x] = ;
f[x] = fa;
for(auto to : G[x]){
if(to == fa) continue;
dfs(to, x, d+);
sz[x] += sz[to];
}
} int main()
{
int n, x, y;
cin>>n;
for(int i = ; i < n; i++){
scanf("%d %d", &x, &y);
G[x].push_back(y);
G[y].push_back(x);
}
dfs(, , );
x = n;
while(x != ){
Q.push_back(x);
x = f[x];
}
Q.push_back();
int ansB = , ansW = , B = , W, temp;
while(){
if(Q.empty()){
ansB += sz[B]--sz[W];
ansW = sz[W] - ansW;
if(ansB <= ansW) cout<<"Snuke"<<endl;
else cout<<"Fennec"<<endl;
return ;
}
temp = B;
B = Q.back(); Q.pop_back();
if(temp != ) ansB += sz[temp]-sz[B]-;
if(Q.empty()) {
ansB += sz[B]--sz[W];
ansW = sz[W] - ansW;
if(ansW <= ansB) cout<<"Fennec"<<endl;
else cout<<"Snuke"<<endl;
return ;
}
W = Q.front(); Q.pop_front();
ansW++;
}
}

ARC078 D.Fennec VS. Snuke(树上博弈)的更多相关文章

  1. 51nod_1490: 多重游戏(树上博弈)

    题目链接 该题实质上是一个树上博弈的问题.要定义四种状态--2先手必胜 1先手必败 3可输可赢 0不能控制 叶子结点为先手必胜态: 若某结点的所有儿子都是先手必败态,则该结点为先手必胜态: 若某结点的 ...

  2. 【AtCoder078D】Fennec VS. Snuke

    AtCoder Regular Contest 078 D - Fennec VS. Snuke 题意 给一个树,1是白色,n是黑色,其它没有颜色.Fennec每次可以染白色点的直接邻居为白色.Snu ...

  3. Fennec VS. Snuke

    Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement Fenne ...

  4. Fennec VS. Snuke --AtCoder

    题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...

  5. AtCoder Beginner Contest 067 D - Fennec VS. Snuke

    D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...

  6. 51nod 1490: 多重游戏(树上博弈)

    题目链接 该题实质上是一个树上博弈的问题.要定义四种状态——2先手必胜 1先手必败 3可输可赢 0不能控制 叶子结点为先手必败态: 若某结点的所有儿子都是先手必败态,则该结点为先手必胜态: 若某结点的 ...

  7. ABC Fennec VS. Snuke

    题目描述 Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N ...

  8. hihocoder1545 : 小Hi和小Ho的对弈游戏(树上博弈&nim博弈)

    描述 小Hi和小Ho经常一起结对编程,他们通过各种对弈游戏决定谁担任Driver谁担任Observer. 今天他们的对弈是在一棵有根树 T 上进行的.小Hi和小Ho轮流进行删除操作,其中小Hi先手. ...

  9. HDU - 5996 树上博弈 BestCoder Round #90

    就是阶梯NIM博弈,那么看层数是不是奇数的异或就行了: #include<iostream> #include<cstdio> #include<algorithm> ...

随机推荐

  1. jquery图片滚动animate.css

    @charset "UTF-8"; /*!Animate.css - http://daneden.me/animateLicensed under the MIT license ...

  2. Hello,移动WEB—Viewport_Meta标签

    二   Viewport meta标签: 语法:<meta name="viewport" content="name=value, name=value" ...

  3. Asp.NET Core 在IIS部署 An assembly specified in the application dependencies manifest was not found

    今天在发布应用的时候,出来了一个报错:An assembly specified in the application dependencies manifest was not found 情况如下 ...

  4. 吐血分享:QQ群霸屏技术教程之霸屏实施细则

    小号,再不养,成本抗不住了;QQ群,再不玩,真的就玩不动啦. 霸屏系列,坚持下来差不多10来篇,最近更新的几篇,算是霸屏系列的更新版,毕竟相当的规则变动了. 经营自己,是一种前瞻能力,霸屏十篇,有多少 ...

  5. HDSF读写文件

    HDFS 读取文件 HDFS的文件读取原理,主要包括以下几个步骤: 1.首先调用FileSystem对象的open方法,其实获取的是一个DistributedFileSystem的   实例. 2.D ...

  6. STM32(3)——外部中断的使用

    1 .简介 ARM Coetex-M3内核共支持256个中断,其中16个内部中断,240个外部中断和可编程的256级中断优先级的设置.STM32目前支持的中断共84个(16个内部+68个外部),还有1 ...

  7. flask(列表实现)

    在 index/views.py 中定义视图函数 在查询的时候,如果用户分类id传0,则不添加分类查询条件 @index_blu.route('/newslist') def get_news_lis ...

  8. Leecode刷题之旅-C语言/python-26.移除元素

    /* * @lc app=leetcode.cn id=27 lang=c * * [27] 移除元素 * * https://leetcode-cn.com/problems/remove-elem ...

  9. asp.net 模拟CURL调用微信公共平台API 上传下载多媒体文件接口

    FormItem类 public class FormItem { public string Name { get; set; } public ParamType ParamType { get; ...

  10. 根据STATUS信息对MySQL进行优化

    mysql> show global status;可以列出MySQL服务器运行各种状态值,我个人较喜欢的用法是show status like '查询值%';一.慢查询mysql> sh ...