Fennec VS. Snuke --AtCoder
题目描述
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
分析:本题最优策略是尽量堵住对手,BFS扫到最后发现谁占据的节点多,谁就会赢。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,x,y,col[],cnt[];
vector<int> map[];
void init(){
cin>>n;
range(i,,n-){
cin>>x>>y;
map[x].push_back(y);
map[y].push_back(x);
}
col[]=,col[n]=;
}
void solve(){
queue<int>q;
q.push(),q.push(n);
while(!q.empty()){
int head=q.front();
q.pop();
++cnt[col[head]];
range(i,,map[head].size()-){
int tmp=map[head][i];
if(col[tmp])continue;
col[tmp]=col[head];
q.push(tmp);
}
}
cout<<(cnt[]<cnt[]?"Fennec":"Snuke")<<endl;
}
int main() {
init();
solve();
return ;
}
Fennec VS. Snuke --AtCoder的更多相关文章
- AtCoder Beginner Contest 067  D - Fennec VS. Snuke
		
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
 - 【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 ...
 - ABC Fennec VS. Snuke
		
题目描述 Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N ...
 - ARC078 D.Fennec VS. Snuke(树上博弈)
		
题目大意: 给定一棵n个结点的树 一开始黑方占据1号结点,白方占据n号结点 其他结点都没有颜色 每次黑方可以选择黑色结点临近的未染色结点,染成黑色 白方同理. 最后谁不能走谁输. 题解: 其实简单想想 ...
 - 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 ...
 - AtCoder Regular Contest 078 D
		
D - Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement F ...
 - すぬけ君の塗り絵 / Snuke's Coloring AtCoder - 2068 (思维,排序,贡献)
		
Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. ...
 
随机推荐
- 使用Spark Streaming + Kudu + Impala构建一个预测引擎
			
随着用户使用天数的增加,不管你的业务是扩大还是缩减了,为什么你的大数据中心架构保持线性增长的趋势?很明显需要一个稳定的基本架构来保障你的业务线.当你的客户处在休眠期,或者你的业务处在淡季,你增加的计算 ...
 - Git-起步
			
Git命令行 只要输入git,Git就会不带任何参数地列出它的选项和最常用的子命令. 要得到一个完整的git子命令列表,可以输入git help --all 显示版本号 git --version 每 ...
 - Java JVM 内存空间解析
			
运行时数据区: 运行时数据区主要分五块,分别是Method Area , VM Stack , Native Method Stack , Heap , program Counter Registe ...
 - Android环境安装简单总结
			
1.安装JDK 参考 http://jingyan.baidu.com/article/215817f7e3f2bd1eda1423f4.html 2.安装android SDK 参考 http:// ...
 - hnust 懒人多动脑
			
问题 F: 懒人得多动脑 时间限制: 1 Sec 内存限制: 128 MB提交: 93 解决: 30[提交][状态][讨论版] 题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每 ...
 - [ecmagnet][python基础]有关git那些事
			
#1 git教程 # 注册git服务器用户,权限-- 注意这个和客户端用户不是一样 # 客户端(linux)提交代码到本地仓库(简单版,了解原理) a.安装git sudo apt-get insta ...
 - redis设置最大内存上限对置换策略的解读
			
现在很少服务器还在使用32位的操作系统了,所以服务器的内存可以接近极限2^64的字节.redis配置文件中有限制最大内存的字段maxmemory,当redis的key达到最大值时,redis会有多种策 ...
 - 【转】tomcat与apache,tomcat与servlet的区别
			
tomcat与apache的区别:(转自:http://blog.csdn.net/longzs/article/details/10959945) 1.apache支持静态页,tomcat支持动态的 ...
 - UVALive 5099 	Nubulsa Expo 全局最小割问题
			
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
 - BZOJ 3990: [SDOI2015]排序(搜索+剪枝)
			
[SDOI2015]排序 Description 小A有一个1-2^N的排列A[1..2^N],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的i(1< ...