sgu - 520 - Fire in the Country(bfs + dfs + 博弈)
来源:互联网 发布:淘宝卖家如何发布宝贝 编辑:程序博客网 时间:2024/05/22 18:29
题意:n个点m条边的无向连通图,开始时结点1起火,火蔓延到其相邻点需1天,开始时有个机器人也在结点1处,但机器人先走了,结点1才起火,Vladimir与Nikolay轮流控制这个机器人,机器人1天也只能移动到另一个相邻点,最后谁不得不让机器人走向火海谁就败,输出胜者。
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=520
——>>搜索中的博弈,策略:让火跟着走,走进死胡同,下一天对手就没得走了(若子状态有一个先手必败状态,那么现在这个状态是先手必胜状态)。
f[i]表示火蔓延到结点i要多少天。
#include <cstdio>#include <cstring>#include <queue>using namespace std;const int maxn = 1000 + 10;int n, m, head[maxn], nxt[maxn<<1], u[maxn<<1], v[maxn<<1], ecnt, f[maxn];void init(){ for(int i = 1; i <= n; i++) head[i] = -1; ecnt = 0;}void addEdge(int uu, int vv){ u[ecnt] = uu; v[ecnt] = vv; nxt[ecnt] = head[uu]; head[uu] = ecnt; ecnt++;}void read(){ int i, uu, vv; for(i = 0; i < m; i++){ scanf("%d%d", &uu, &vv); addEdge(uu, vv); addEdge(vv, uu); }}void bfs(){ queue<int> qu; while(!qu.empty()) qu.pop(); f[1] = 1; qu.push(1); while(!qu.empty()){ int u = qu.front(); qu.pop(); for(int e = head[u]; e != -1; e = nxt[e]) if(!f[v[e]]){ f[v[e]] = f[u] + 1; qu.push(v[e]); } }}void fire(){ memset(f, 0, sizeof(f)); bfs();}bool dfs(int u){ for(int e = head[u]; e != -1; e = nxt[e]) if(f[v[e]] == f[u] + 1 && !dfs(v[e])) return 1; return 0;}int main(){ while(scanf("%d%d", &n, &m) == 2){ init(); read(); fire(); if(dfs(1)) printf("Vladimir\n"); else printf("Nikolay\n"); } return 0;}
- sgu - 520 - Fire in the Country(bfs + dfs + 博弈)
- SGU 520 Fire in the Country 博弈SG函数(或者YY一下)
- Gym 101246DFire in the Country (dfs暴力博弈)
- FZU 2150 Fire Game (DFS + BFS)
- FZU 2150 Fire Game(dfs+bfs)
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest Fire in the Country(博弈论+搜索)
- 博弈搜索练习-BFS&DFS
- FZU 2150 Fire Game(DFS+BFS)
- FZU 2150 Fire Game (暴搜/ BFS+DFS)
- Fire Game(BFS)
- Fire Game (BFS)
- Fire!(bfs) UVA
- UVa11624-Fire!(bfs)
- The most happiest country in the world
- HDU4101 Ali and Baba (bfs+dfs+博弈)
- Fire Net(DFS)
- Fire Net (DFS)
- SGU 202 The Towers of Hanoi Revisited (DFS+预处理)
- Poj 3292(筛法变形)
- hdu 4605 Magic Ball Game
- JavaScript 框架页面互相访问
- Windows 逻辑坐标和设备坐标
- hive 调用栈
- sgu - 520 - Fire in the Country(bfs + dfs + 博弈)
- 黑马程序员——Java基础
- 营运与创新的拉锯 ERP与PLM之比较
- (step 3.1.6)hdu 2501(Tiling_easy version)
- Linux进程通信之POSIX共享内存
- 细细品味C#——Timer及多线程编程
- 如何划分PLM与ERP之间界线?
- Jeff Atwood倾情推荐——程序员必读之书
- hdu 4614 Vases and Flowers