poj 2599 A funny game 博弈论
思路:无向图,走过的点不能在走。dfs搞定……
再就是后继中有必败点的为必胜点!
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int ans;
vector<int>p[];
bool vis[];
int dfs(int n)
{
for(int i=;i<p[n].size();i++){
if(!vis[p[n][i]]){
vis[p[n][i]]=;
if(!dfs(p[n][i])){
ans=p[n][i];
return ;
}
vis[p[n][i]]=;
}
}
return ;
}
int main()
{
int n,m,a,b;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<n;i++) p[i].clear();
memset(vis,,sizeof(vis));
for(int i=;i<n;i++){
scanf("%d%d",&a,&b);
p[a].push_back(b);
p[b].push_back(a);
}
vis[m]=;
if(dfs(m)) printf("First player wins flying to airport %d\n",ans);
else printf("First player loses\n");
}
return ;
}
poj 2599 A funny game 博弈论的更多相关文章
- POJ.1067 取石子游戏 (博弈论 威佐夫博弈)
POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...
- POJ 2599 A funny game#树形SG(DFS实现)
http://poj.org/problem?id=2599 #include<iostream> #include<cstdio> #include<cstring&g ...
- POJ 2348 Euclid's Game 博弈论
http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...
- [poj 3537]Crosses and Crosses(博弈论)
题目:http://poj.org/problem?id=3537 题意:给你n个格子,两个人依次在n个格子的任意空位置画"X",谁如果画了一个后,3个X连在了一起,那么那个人就获 ...
- POJ 3553 Light Switching Game 博弈论 nim积 sg函数
http://poj.org/problem?id=3533 变成三维的nim积..前面hdu那个算二维nim积的题的函数都不用改,多nim积一次就过了...longlong似乎不必要但是还是加上了 ...
- POJ 2425 A Chess Game 博弈论 sg函数
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...
- POJ 2484 A Funny Game 博弈论 对称博弈
http://poj.org/problem?id=2484 1和2时Alice必胜,3时Bob必胜,其他情况下Bob只需要在Alice取过之后取一次将剩下的硬币链平均分为两份,然后Alice怎么取B ...
- poj 3537 Crosses and Crosses 博弈论之grundy值
题意: 给1*n的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢.问先手必胜还是必败. 分析: 求状态的grundy值(也就是sg值),详细怎么求详见代码.为什么这么求要自己想的,仅仅可意会(别人都说 ...
- poj 3537 Crosses and Crosses 博弈论
思路:每次画X之后都会形成2个子游戏,即i-3和n-i-2. 代码如下: #include<iostream> #include<cstdio> #include<cma ...
随机推荐
- Knockout.Js学习目录
1.Knockout.Js(简介) 2.Knockout.Js(监控属性Observables) 3.Knockout.Js(属性绑定) 4.Knockout.Js(事件绑定) 5.Knockout. ...
- TFT LCD 参数详解
我的板子设置HCLK=100M因此CLKVAL= int(HCLK/(VCLK*2)-1),其中VCLK即上图的DCLK=6.4M, CLKVAL="int"(100/12.8-1 ...
- ABAP自定义类的构造方法
REPORT ytest_011. *----------------------------------------------------------------------* * CLASS z ...
- [shell基础]——整数比较;字符串比较;文件测试;逻辑测试符
整数比较方法一:[ ] 或 [[ ]] (1) 此方法需要使用整数比较运算符.[标注:equal 等于 greater 大于 less-then 小于] (2) 使用时一定要注意前后一 ...
- [shell基础]——cut命令
cut命令常见选项
- Android -- View
setContentView 只要你使用过Activity ...
- Daily Scrum2
今天我们小组开会内容分为以下部分: part 1: 之前的失败教训: part 2: 针对Anti-spam and anti-abuse module模块的任务分工: part 3: 之后小组成员必 ...
- C++输出四则运算设计题的思路
一,(1)题目避免重复:使用srand(seed)函数进行随机化,随seed的不同,可以产生不同的随机数二,(1)控制数量:输入变量n控制三,(1)控制是否有乘除:(chengchu=0,没有乘除:c ...
- 封装insertAfter、addClass、格式化时间
insertAfter,在JS节点操作中,并没有insertAfter方法,因此需要重新封装 function insertAfter(newEle,targetNode) { var oParent ...
- android 怎么动态设置button 的style
网上找了很多,还是没有直接的解决办法,button没有setstyle这个方法.因此我的解决办法如下: 直接动态设置各个属性 Button themeBtn = new Button(this); t ...