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 ...
随机推荐
- settings配置数据库和日志
数据库的配置: 一.mysql配置 pip下载pymysql,用于mysql和django的连接. 在init.py上配置pymsqy. import pymysql pymysql.install_ ...
- html_js
<!-- js的特点:别名脚本 -由浏览器内置的JavaScript引擎执行代码. -解析执行:事先不编译,逐行执行 -面向对象:内置大量的现成对象 适宜: -客户端的数据计算:不需要保存和提交 ...
- SpringCloud学习之手把手教你用IDEA搭建入门项目(二)
本篇博客是承接上一篇<手把手教你用IDEA搭建SpringCloud入门项目(一)>,不清楚的请到我的博客空间查看后再看本篇博客 1)先创建一个Eureka服务注册中心模块,用来作为服务的 ...
- VMware Workstation 12 PRo密钥
注意:手动输入(起初复制输入,一个都没成功,不要偷懒哦) VMware Workstation 12序列号: 5A02H-AU243-TZJ49-GTC7K-3C61N
- 毕设问题 ---链接Dreamweaver和eclipse
在eclipse里面新建站点 https://blog.csdn.net/Slash_youth 我是一个搬运工 哈哈哈
- CSS(3)之 less 和rem
less 预编译脚本语言. LESS 语法 less语法2 LESS中文 rem rem的适配原理 rem 是相对于页面根源素html的字体大小的一个尺寸单位 页面内容可以使用rem为单位,那么htm ...
- 吴裕雄--天生自然MySQL学习笔记:MySQL 排序
从 MySQL 表中使用 SQL SELECT 语句来读取数据. 如果我们需要对读取的数据进行排序,我们就可以使用 MySQL 的 ORDER BY 子句来设定你想按哪个字段哪种方式来进行排序,再返回 ...
- SQL基础教程(第2版)第1章 数据库和SQL
● 数据库有很多种类,本书将介绍如何使用专门的 SQL语言来操作关系数据库.● 关系数据库通过关系数据库管理系统(RDBMS)进行管理. 根据 SQL 语句的内容返回的数据同样必须是二维表的形式,这也 ...
- MySQL--InnoDB 体系架构
InnoDB 体系架构 后台线程 Master Thread Master Thread 是一个非常核心的后台线程,主要负责将缓冲池中的数据异步刷新到磁盘,保证数据的一致性,包括脏页的刷新.合并插入缓 ...
- PPT制作不加班的十个小窍门
五个一键: 情景一: 上司:小万,什么字体啊这是,全部换成微软雅黑. 一键替换字体: 单击任意文本框——开始菜单栏——替换(下拉三角)——替换字体——替换为——替换. 情景二: 上司:小万,“咖啡 ...