AtCoder Regular Contest 078 D
D - 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
题意:有一颗树,第一个点颜色为1,最后一点颜色为2,1颜色可以将它相邻的点染色成1颜色,2颜色同理,现在F先手,S后手,最后不能染色算输,最后谁赢了
解法:
1 F开始染色第1点和它周围点(ABC....),然后S开始染色第N点和它周围点(abc..),然后F染色A点和A点相邻点,然后S染色a点和a点相邻点...
2 明白了吗?最后谁染色的点多谁就赢了
3 这里染色讲究先后,我们用队列广搜
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#define N 100005
using namespace std;
vector <int> vec[N];
int color[N];
int main(){
queue <int> que;
int n , x , y;
scanf("%d",&n);
for(int i = ; i < n ; i ++){
scanf("%d%d",&x,&y);
vec[x].push_back(y);
vec[y].push_back(x);
}
color[] = , color[n] = ;
int cnt[] = { , };
que.push() ;
que.push(n);
while(!que.empty()){
int x = que.front();
que.pop();
cnt[color[x]] ++; for(int i = ; i < vec[x].size() ; i ++){
int v = vec[x][i];
if(color[v]) continue;
color[v] = color[x];
que.push(v);
}
}
if(cnt[] >= cnt[]){
printf("Snuke\n");
}else{
printf("Fennec\n");
} }
AtCoder Regular Contest 078 D的更多相关文章
- AtCoder Regular Contest 078
我好菜啊,ARC注定出不了F系列.要是出了说不定就橙了. C - Splitting Pile 题意:把序列分成左右两部分,使得两边和之差最小. #include<cstdio> #inc ...
- AtCoder Regular Contest 078 C
C - Splitting Pile Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snu ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
- AtCoder Regular Contest 095
AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...
- AtCoder Regular Contest 102
AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...
随机推荐
- Python 参数校验的进化
Python 函数参数魔法 事情的起因是感觉目前项目中的参数校验方法写的太简单了,很多时候需要在server层再if else处理,于是就动手准备写一个好用一点的,可以自定义校验参数规则的参数校验器, ...
- NOIP2010_T4_引水入城 bfs+贪心
在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 N 行 M 列的矩形,如上图所示,其中每个格子都代表一座城 市,每座城市都有一个海拔高度.为了使 ...
- html5--4-4 audio元素/格式的转换
html5--4-4 audio元素/格式的转换 学习要点 掌握audio元素的用法 视频/音频文件的格式转换 当前,audio 元素支持三种音频格式: Ogg 免费, 支持的浏览器:Firefox. ...
- java-执行dos命令
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOExce ...
- 如何应用AutoIt,把局域网中所有的机器名展示在一个combox中?
有时候,我们会遇到以下情况: 你想与局域网中的某台机器建立连接,你就需要输入对方的机器名. 现在我比较懒,我不想输入对方的机器名,或者对方的机器名很难记住,那怎么办呢? 那就做一个combox在页面上 ...
- python3 分布式进程(跨机器)BaseManager(multiprocessing.managers)
A机器负责发送任务和接受结果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #ta ...
- tabbar
1 tabbar不显示的问题: 命名在app.json中配置了tabbar但是不显示可能的问题: app.json中的pages中第一个路径没有在tabbar中设置 原因:app.json中配置的pa ...
- 网络应用软件结构-----CS与BS结构(网络基本知识小结)
1.网络的大致结构 2.网络编程 通过直接或间接地使用网络通讯的协议实现计算机与计算机之间的通讯.在TCP/IP协议层主要麦网络主机的定位,数据传输的路由,由IP地址可以唯一地确定Internet上的 ...
- 开源跨平台声波传输库:Sonic
简介 [Sonic](https://github.com/linyehui/sonic) 是一个跨平台的声波传输库(iOS & Android),技术上类似于[chirp](http://c ...
- 多叉树结构:JSON数据解析(二)
多叉树结构:JSON数据解析(二) 在上篇文章中提到了JSON数据解析的基本方法,但是方法效率太低,这里接着上篇文章写写如何利用多叉树结构,定义对象,实现JSON数据字段快速随机访问. JSON数据通 ...