ABC Fennec VS. Snuke
题目描述
On the board, there are N cells numbered 1 through N, and N−1 roads, each connecting two cells. Cell ai is adjacent to Cell bi through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.
Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:
Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black.
Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white.
A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
Constraints
2≤N≤105
1≤ai,bi≤N
The given graph is a tree.
输入
N
a1 b1
:
aN−1 bN−1
输出
样例输入
7
3 6
1 2
3 1
7 4
5 7
1 4
样例输出
Fennec
提示
For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.
思维题
题意:有一棵树,编号1~n,1为黑色,n为白色,其余尚未染色,Fennec先开始染黑色相邻的点,Snuke后染白色相邻的点,
交替反复,谁无法染色谁就输,二者都采取最优策略,问最后的胜者。
最优解就是尽可能把路堵住,把相邻的两个点染色,这样只有两种颜色染色点中间是互争的,其他的则为该染色点的势力范围。
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int s[maxn];
int aans,bans;
vector<int>vt[maxn];
int main(){
int n,x,y;
ios::sync_with_stdio(false);
cin.tie();
cin>>n;
for(int i=;i<n;i++){
cin>>x>>y;
vt[x].push_back(y);
vt[y].push_back(x);
}
queue<int>q;
s[]=;
s[n]=;
q.push();
q.push(n);
while(!q.empty())
{
int temp=q.front();
q.pop();
for(int i=;i<vt[temp].size();i++){
if(s[vt[temp][i]]) continue;
if(s[temp]==)
aans++;
else bans++;
s[vt[temp][i]]=s[temp];
q.push(vt[temp][i]);
}
}
if(bans>=aans) cout<<"Snuke"<<endl;
else cout<<"Fennec"<<endl;
return ;
}
ABC Fennec VS. Snuke的更多相关文章
- 【AtCoder078D】Fennec VS. Snuke
AtCoder Regular Contest 078 D - Fennec VS. Snuke 题意 给一个树,1是白色,n是黑色,其它没有颜色.Fennec每次可以染白色点的直接邻居为白色.Snu ...
- Fennec VS. Snuke
Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement Fenne ...
- Fennec VS. Snuke --AtCoder
题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
- ARC078 D.Fennec VS. Snuke(树上博弈)
题目大意: 给定一棵n个结点的树 一开始黑方占据1号结点,白方占据n号结点 其他结点都没有颜色 每次黑方可以选择黑色结点临近的未染色结点,染成黑色 白方同理. 最后谁不能走谁输. 题解: 其实简单想想 ...
- AtCoder Regular Contest 078 D
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
- AtCoder Regular Contest 078
我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...
- 【AtCoder】ARC078
C - Splitting Pile 枚举从哪里开始分的即可 #include <bits/stdc++.h> #define fi first #define se second #de ...
- 【思维】ABC
题目描述 You are given a string s consisting of A, B and C.Snuke wants to perform the following operatio ...
随机推荐
- sql优化从300秒到7秒
原始sql select b.jd 街道,b.rglm 楼宇,zzrl 楼宇编号,count(oname) 入楼企业总数, (select count(oname) from ${tablename} ...
- win10编译jpeglib
jpeglib看名字都大概知道和图像格式jpg或jpeg有关了,是一个常用的图像处理软件都会依赖的开源库. 首先去官网下载jpeglib的源码,直接取这里下载:http://www.ijg.org/f ...
- M内核迎来大BOSS,ARM发布Cortex-M55配NPU Ethos-U55 ,带来无与伦比的性能提升
说明: 全球顶级嵌入式会展Embedded Word2020这个月底就开了,各路厂家都将拿出看家本领. 先回顾下去年的消息: 1.去年年初的时候ARM发布Armv8.1-M架构,增加了Arm Heli ...
- 经典线段树 UVALive 3938/UVA 1400
题意:就是相当于动规里面的求最大连续子串,不同的是,这里需要读入一个区间x,y,输出的区间 a,b 且x<=a<=b<=y,使得a b的连续子串最长,而且询问次数达到了10的五次方. ...
- NodeJS框架一览
NodeJS 框架一览 Express 当你使用Node.js构建web应用程序时, Express通常被视为事实上的Web服务器.它的哲学(一个可以使用中间件包扩展的简约核心)是大多数Node.js ...
- Python3中bytes和HexStr之间的转换
1 Python3中bytes和HexStr之间的转换 ByteToHex的转换 def ByteToHex( bins ): """ Convert a byte st ...
- 计蒜客 置换的玩笑(DFS)
传送门 题目大意: 小蒜头又调皮了.这一次,姐姐的实验报告惨遭毒手. 姐姐的实验报告上原本记录着从 1 到 n 的序列,任意两个数字间用空格间隔.但是“坑姐”的蒜头居然把数字间的空格都给删掉了,整个数 ...
- 理解自动梯度计算autograd
理解自动求导 例子 def f(x): a = x * x b = x * a c = a + b return c 基于图理解 代码实现 def df(x): # forward pass a = ...
- 吴裕雄--天生自然 PHP开发学习:高级
<?php echo date("Y/m/d") . "<br>"; echo date("Y.m.d") . " ...
- 你需要了解的JIT Debugging
原总结debug调试dump转储文件windbgprocdumpJIT Debugger 如果你还不清楚什么是转储文件,不知道什么时候需要转储文件,请参考转储文件系列文章的第一篇 -- 转储文件知多少 ...