UVA 11927 - Games Are Important(sg函数)
来源:互联网 发布:坐标系转换软件 编辑:程序博客网 时间:2024/06/13 12:51
UVA 11927 - Games Are Important
题目链接
题意:给定一个有向图,结点上有一些石头,两人轮流移动石头,看最后谁不能移动就输了,问先手还后手赢
思路:求出每个结点的sg函数,然后偶数个石头结点可以不用考虑,因为对于偶数情况,总步数肯定能保证是偶数,所以只要考虑奇数情况的结点
代码:
#include <stdio.h>#include <string.h>#include <algorithm>#include <vector>using namespace std;const int N = 1005;int n, m, sg[N];vector<int> g[N];int dfs(int u) {if (sg[u] != -1) return sg[u];if (g[u].size() == 0) return sg[u] = 0;bool vis[N];memset(vis, false, sizeof(vis)); for (int i = 0; i < g[u].size(); i++)vis[dfs(g[u][i])] = true;for (int i = 0; ; i++)if (!vis[i]) return sg[u] = i;}int main() {while (~scanf("%d%d", &n, &m) && n || m) {int u, v;memset(g, 0, sizeof(g));memset(sg, -1, sizeof(sg)); while (m--) { scanf("%d%d", &u, &v); g[u].push_back(v); } for (int i = 0; i < n; i++) dfs(i); int ans = 0, num; for (int i = 0; i < n; i++) { scanf("%d", &num); if (num&1) ans ^= sg[i]; } printf("%s\n", ans == 0? "Second":"First"); }return 0;}
1 0
- UVA 11927 - Games Are Important(sg函数)
- UVA - 11927 Games Are Important (SG)
- uva 11927 - Games Are Important(组合游戏+记忆化)
- uva 10561 Treblecross (SG函数)
- UVA 10561 - Treblecross(博弈SG函数)
- 【UVA 10561】 Treblecross|博弈论|SG函数
- SG函数(Treblecross游戏,UVA 10561)
- why software are important
- "Friends" are so important.
- Memory Access Patterns Are Important
- uva 1378 - A Funny Stone Game sg函数
- UVa 12293 Box Game(博弈,SG函数)
- sg函数_______A Funny Stone Game(uva 1378)
- UVA - 10561 Treblecross (博弈数学&SG函数)
- UVA-1482 Playing With Stones(SG函数打表找规律)
- UVA 11892 浅谈无SG函数纯分析博弈论
- Uva - 1610 - Party Games
- uva 1610Party Games
- nmap
- Outlook 备份数据、账户、设置
- Codeforces 39E What Has Dirichlet Got to Do with That? 博弈+记忆化搜索
- Java性能的优化
- 初学Swift
- UVA 11927 - Games Are Important(sg函数)
- 机器学习之支持向量机(svm)
- 从BAE到SAE,从SAE又回到BAE
- ajax跨域和js跨域解决方案
- LightOJ 1095 数学
- hdu1052Tian Ji -- The Horse Racing(贪心算法)
- 面试智力题(二)
- Linux_c编程——copy函数
- 设计模式-Simple Factory 简单工厂模式(静态工厂)