UVALive 7278 Game of Cards
来源:互联网 发布:网络办理贷款 编辑:程序博客网 时间:2024/05/16 08:30
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5330
题意:有n堆卡片,每张卡片上面都有一个数字(1~10),每次操作选择一堆卡片,取走最上面(0~k)张,一堆至少要留一张,然后再取这堆卡片当前堆顶卡片上面的数字张数。谁不能取就输了。
思路:组合游戏博弈,直接暴力计算出每一堆的sg函数即可。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod 100000007const int maxn = 1009;int p,k;int a[maxn];int cal(int n){ int sg[maxn]; int temp[50]; Clean(sg,0); rep(i,1,n) { Clean(temp,false); rep(j,0,k) if ( i > j && i - j >= a[i-j] ) temp[ sg[i-j-a[i-j]] ] = true; int j = 0; while(temp[j]) j++; sg[i] = j; } return sg[n];}void solve(){ int m; int ans = 0; rep(i,1,p) { scanf("%d",&m); rep(j,1,m) scanf("%d",&a[j]); ans ^= cal(m); } puts(ans?"Alice can win.":"Bob will win.");}int main(){ while( cin>>p>>k ) { solve(); } return 0;}
0 0
- UVALive 7278 Game of Cards
- UVALive-7278 - Game of Cards【博弈】【sg定理】
- Game of Cards Gym
- B. Game of Credit Cards
- 777Game of Credit Cards
- Codeforces777B Game of Credit Cards
- 【codeforces 777B】Game of Credit Cards
- Codeforces 777B-Game of Credit Cards
- codeforces 777b Game of Credit Cards
- CF777B:Game of Credit Cards(贪心)
- Game of Credit Cards (Codeforces-777B)
- UVALIVE 7505 Hungry Game of Ants DP
- 【CodeForces 777B】Game of Credit Cards(贪心+排序)
- Codeforces Round #401 (Div. 2) B. Game of Credit Cards
- codeforces 777 B. Game of Credit Cards (排序乱搞)
- GYM 101128 G.Game of Cards(博弈论)
- CodeForces 777B Game of Credit Cards【贪心】
- codeforces 777B Game of Credit Cards (贪心)
- UML图学习之二 类图
- POJ2549-Sumsets
- C++之string类型详解
- UML图学习之三 状态图
- UML图学习之四 活动图
- UVALive 7278 Game of Cards
- AVL树详解(附c++代码)
- UML图学习之五 序列图(顺序图)和协作图
- Android开发bug日记
- AE、IDL开发问题锦集
- UML图学习之六 构件图
- 机器学习入门读书笔记二(k-近邻算法 kNN) 上
- c++:日历的实现
- UML图学习之七 部署图(Component Diagram)