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. ...
随机推荐
- jmeter XML格式的结果中各属性的含义
最近在搞jmeter,生成xml的测试报告,对报告字段进行解释,可能是自己不会找,网上资源不多,好不容易找到的,记录下来: 感谢博主:http://blog.163.com/zhang_jing/bl ...
- 菜鸟学Linux - Hard Link与Symbolic Link
在学习Hard Link与Symbolic Link之前,需要大概了解一下inode与data block.在Linux的文件系统中,一个文件对应一个inode与若干个data block.inode ...
- Mysql密码加密方式
以Mysql 4.1版本为分界线,两种加密方式 Mysql323加密:(16位) select old_password('root'); //Mysql自带加密函数old_password(str ...
- C# datagridview列绑定类中类的属性
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://www.cnblogs.com/linghaoxinpian/p/5906374. ...
- cogs:1619. [HEOI2012]采花/luogu P2056
1619. [HEOI2012]采花 ★★☆ 输入文件:1flower.in 输出文件:1flower.out 简单对比时间限制:5 s 内存限制:128 MB [题目描述] 萧薰儿是 ...
- laravel5.2总结--响应
1 基本响应 1.1 返回一个字符串,指定的字符串会被框架自动转换成 HTTP 响应. Route::get('/', function () { return 'Hello World'; }) ...
- leetcode 【 Insertion Sort List 】 python 实现
题目: Sort a linked list using insertion sort. 代码:oj测试通过 Runtime: 860 ms # Definition for singly-linke ...
- jmeter+ANT+Jekins性能自动生成测试报告脚本(模板),加入:Median TIme、90%、95%、99%、QPS、以及流量显示
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/T ...
- python-day4-内置函数2
摘要:python中有好多可用性特别强的内置函数,熟练掌握对于以后的编程过程中有很大的帮助~~~~ callable函数.chr函数与ord函数.random函数.compile函数.evec与eva ...
- ThinkPHP5 配置文件
配置目录 系统默认的配置文件目录就是应用目录(APP_PATH),也就是默认的application下面,并分为应用配置(整个应用有效)和模块配置(仅针对该模块有效). ├─application 应 ...