Fennec VS. Snuke
Fennec VS. Snuke
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
Fennec and Snuke are playing a board game.
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.
Input
Input is given from Standard Input in the following format:
N
a1 b1
:
aN−1 bN−1
Output
If Fennec wins, print Fennec
; if Snuke wins, print Snuke
.
Sample Input 1
7
3 6
1 2
3 1
7 4
5 7
1 4
Sample Output 1
Fennec
For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.
Sample Input 2
4
1 4
4 2
2 3
Sample Output 2
Snuke //n个格子,编号为1-n,1开始是黑色,n开始是白色。有m条边,且为树,说明格子的相邻情况,然后Fnc先开始涂黑色,涂色规则是:格子没被涂过色,并且相邻有黑色格子
然后Snu涂色,类似的规则,snu涂白色,相邻要有白色。轮流涂色,直到有一方不能涂了,另一方获胜。 显然,他们玩游戏会采取这样的策略,fnc先向着n点去涂色,snu向着1点去涂色,这样可以尽可能获得更多的地盘,然后就是比谁的地盘大咯
用神奇DFS实现
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 100010 int n;
int total;
vector<int> G[MX];
int colr[MX]; void DFS(int x,int pre,int c,int &tot)
{
if (colr[x]==-c) return;
tot++;
for (int i=;i<G[x].size();i++)
if (G[x][i]!=pre)
DFS(G[x][i],x,c,tot);
} void dfs(int u,int pre,int s,int &ok)
{
if (u==n)
{
ok=s;
return;
}
for (int i=;i<G[u].size();i++)
{
if (ok) break;
if (G[u][i]!=pre)
dfs(G[u][i],u,s+,ok);
}
if (ok)
{
if (u!=&&s<=ok/) colr[u]=;
if (u!=n&&s>ok/) colr[u]=-;
}
return;
} int main()
{
scanf("%d",&n);
for (int i=;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
colr[]=; //hei
colr[n]=-;//bai int ok=;
dfs(,-,,ok);
/*
for (int i=1;i<=n;i++)
printf("%d ",colr[i]);
printf("\n");
*/ int num_1=;
DFS(,-,,num_1);
int num_2=;
DFS(n,-,-,num_2);
if (num_1-num_2>=)
printf("Fennec\n");
else
printf("Snuke\n");
return ;
}
Fennec VS. Snuke的更多相关文章
- 【AtCoder078D】Fennec VS. Snuke
AtCoder Regular Contest 078 D - Fennec VS. Snuke 题意 给一个树,1是白色,n是黑色,其它没有颜色.Fennec每次可以染白色点的直接邻居为白色.Snu ...
- 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 ...
- 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 Subway Trip
すぬけ君の地下鉄旅行 / Snuke's Subway Trip Time limit : 3sec / Memory limit : 256MB Score : 600 points Problem ...
随机推荐
- B5:责任链模式 Chain Of Responsibility
使多个对象都有机会处理处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这个对象连成一条链,并沿着该链处理请求,直到有一个对象能够处理它为止. 相当于switch/case,在客户端指定了每一链 ...
- CentOS 6.4 图文安装教程(有些设置大部分教程没出现过)
http://www.jb51.net/os/78318.html CentOS 6.4 下载地址: http://www.jb51.net/softs/78243.html 1.首先,要有一张Cen ...
- python基础语法(四)
--------------------------------------------接 Python 基础语法(三)---------------------------------------- ...
- antd-design LocaleProvider国际化
1.LocaleProvider 使用 React 的 context 特性,只需在应用外围包裹一次即可全局生效. import { LocaleProvider } from 'antd'; imp ...
- The Unix Tools Are Your Friends
The Unix Tools Are Your Friends Diomidis Spinellis IF, ON MY WAY TO EXILE ON A DESERT ISLAND, I had ...
- shell脚本监控调度器/proc进程是否运行(嵌套循环)
/proc/<pid>/schedstat $/schedstat First: , Second:time spent waiting on a runqueue,这个值与上面的se.w ...
- 在php中如何用 union all统计总条数?
网上使用union all 查询记录总条数的参考资料比较少,所以记录下来,以便有同样需求的人使用. $rs_num = Db::query("select sum(a.b) as num f ...
- Nginx编译安装第三方模块http_substitutions_filter_module2222
Nginx编译安装第三方模块http_substitutions_filter_module Rming -- 阅读 安装 Http 编译 module filter nginx 模块 >> ...
- 李洪强经典面试题53-Swift
李洪强经典面试题53-Swift Swift 网上有很多Swift的语法题,但是Swift现在语法还未稳定,所以在这里暂时不贴出语法题,可以自行搜索. Swift和Objective-C的联系 Swi ...
- ex:0602-169 遇到不完整或无效的多字节字符,转换失败
错误原因:在AIX系统中,用vi命令编辑文件,出现rt错误,是因为AIX系统不识别文件编码格式. 解决方法:建议重新新建一个编码格式为ASC的文件,再重新上传到AIX系统中,或者改变访问linux的客 ...