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 ...
随机推荐
- ural 1057 Amount of degrees 【数位dp】
题意:求(x--y)区间转化为 c 进制 1 的个数为 k 的数的出现次数. 分析:发现其满足区间减法,所以能够求直接求0---x 的转化为 c 进制中 1 的个数为k的数的出现次数. 首先用一个数组 ...
- Oracle数据类型,函数与存储过程
字符串类型 固定长度:char nchar n 表示Unicode编码 可变长度: varchar2 nvarchar2 数字类型:number(P,S)P:整数位数,S小数位数 ...
- pngCanvas 是一个使用纯Python代码的生成png图像的工具
#!/usr/bin/env python """Simple PNG Canvas for Python - updated for bytearray()" ...
- 我对GFWed的一些自己的见解
首先来听听维基百科对GFWed的说明 防火长城(英语:Great Firewall of China.经常使用简称:GFW,中文也称中国国家防火墙或防火长城[1],中国大陆民众俗称防火墙[2].功夫网 ...
- Spring整合Activiti工作流
代码地址如下:http://www.demodashi.com/demo/11911.html 一. 前期准备 安装必要的开发环境 eclipse/intellij+maven 3.5.x + tom ...
- 转:EMQ(emqttd) 2.x 安装和使用(物联网传输控制协议的Broker)
支持下国产开源. MQTT物联网传输控制协议:<MQTT-3.1.1-CN.pdf> 下载:emqttd-centos64-v2.0-rc.2-20161019.zip 安装: $ unz ...
- CentOS-6.*安装配置SVN
安装说明 系统环境:CentOS-6.3 安装方式:yum install (源码安装容易产生版本兼容的问题) 安装软件:系统自动下载SVN软件 检查已安装版本 #检查是否安装了低版本的SVN [ro ...
- PHP--关于模板的原理和解析(php模板原理)
此内容用作笔记,以备日后查看,此内容为学习李炎恢课程而来,并非自己所创,如有问题请私信~ 将PHP代码和静态HTML代码进行分离,使代码的可读性和维护性得到显著提高. 使用模板引擎: 我们所说的模板是 ...
- CentOS设置sendmail发件人,让sendmail不显示通过XXX代发
0.有一个十分快速的方法 命令:hostname itzhanzhang.com,但是重启后会失效,于是请接着往下看一劳永逸的方法: 1.设置你的主机名 默认的主机名是类似于“VM_24_76_cen ...
- 学习笔记 - Unity是如何将你的项目发布到如此多的平台的?
很多Unity的开发者是不是都会觉得Unity能把项目导出发布到那么多不同的平台上运行是件很牛X的事情?那么你有没有想过Unity是如何做到的呢?本文就来大体的聊一聊Unity做的这件神奇的事情. 概 ...