POJ 2599 A funny game
来源:互联网 发布:淘宝美工是做什么工作 编辑:程序博客网 时间:2024/06/06 06:54
POJ 2599 A funny game
树上的dp博弈,很easy的。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<set>#include<queue>#include<map>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define CLR(a) memset((a),0,sizeof((a)))#define pb push_back#define mp make_pair#define ins insert#define F first#define S second#define bug puts("Oh Here!");#define nMax 2010#define oo 0x7fffffff#define eps 1e-8#define LL long long#define Vec vector<int>#define Pai pair<int,int>class Tree{public: int first[nMax],nxt[nMax],to[nMax],e; int vis[nMax],n,win[nMax],place[nMax]; void init(){ memset(first,-1,sizeof(first)); memset(vis,0,sizeof(vis)); memset(place,-1,sizeof place ); e=0; } void addadge(int u,int v){ to[e]=v;nxt[e]=first[u];first[u]=e;e++; to[e]=u;nxt[e]=first[v];first[v]=e;e++; } void dfs(int u){ win[u]=0; vis[u]=1; for(int i=first[u];i!=-1;i=nxt[i])if(!vis[to[i]]){ dfs(to[i]); if(win[to[i]]==0) { win[u]=1; if(place[u]==-1 || place[u]>to[i]) place[u]=to[i]; } } return ; }};void sovle(int n,int k){ Tree p; p.n=n; p.init(); for(int i=1,u,v;i<n;i++) { scanf("%d%d",&u,&v); p.addadge(u,v); } p.dfs(k); if(p.win[k]){ printf("First player wins flying to airport %d\n",p.place[k]); }else { printf("First player loses\n"); }}int main(){#ifndef ONLINE_JUDGE// freopen("input.txt","r",stdin);#endif int n,k; while(~scanf("%d%d",&n,&k)){ sovle(n,k); } return 0;}
- POJ 2599 A funny game
- POJ 2599 A funny game
- poj 2599 A funny game
- poj A Funny Game
- POJ 2599 A funny game [DFS博弈]
- POJ 2599 A funny game (搜索,博弈)
- POJ-2484-A Funny Game
- poj 2484 A Funny Game
- poj-2484 A Funny Game
- poj 2484 A Funny Game
- POJ 2484 A Funny Game
- poj 2484 A Funny Game
- POJ - 2484 A Funny Game
- poj 2484 A Funny Game
- POJ 2484 A Funny Game
- POJ 2484 - A Funny Game
- POJ 2484 A Funny Game
- POJ 2484:A Funny Game
- POJ 3162 Walking Race (DFS + 线段树)
- 使用OpenCV实现WebCam摄像头保存JPEG图片(改良3版) Ubuntu
- unity3D 物体在三个球之间转圈
- Linux系统学习笔记:虚拟存储器
- Mysql学习笔记
- POJ 2599 A funny game
- Linux系统学习笔记:文件I/O
- java读取数据库中的错误:"Unhandled exception type SQLException"
- 一键安装 BitNamRedmine配置GIT
- Linux系统学习笔记:文件、目录、用户
- 2013年暑假小结
- HDU 4588 Count The Carries 题解
- Linux系统学习笔记:进程
- [多线程]windows线程小结