UVALive-7278 - Game of Cards(sg函数)
2017-03-30 16:29
405 查看
UVALive-7278 - Game of Cards
题目大意:A、B两个人玩游戏。A先手,问最后谁赢。
游戏规则:
给出n堆纸牌,可任意选择其中一堆,记为x
在x的顶部可取走[0,k]张纸牌,该堆纸牌至少留下一张
x剩下来的纸牌中,记顶部的纸牌值为y,则移除最顶部的y张纸牌(即该堆至少还剩下y张纸牌才是合法)
如果有人不能进行合法移动,则输了。
题目思路:主要是写SG函数,每一堆的sg函数都不同。最后每一堆 ans ^= sg
,即可。比赛的时候没读懂题,要不是可以出的。。。基础的sg吧。。只不过每一堆sg都不一样,类似于组合游戏吧
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e3 + 20;
int book[maxn], sg[maxn], a[maxn], k;
void get_sg(int n) //求每一堆sg
{
for(int i = 1; i <= n; i++)
{
memset(book, 0, sizeof(book));
for(int j = 0; j <= k; j++) //枚举所有可能到达的地方
{
if(i-j <= 0)
break;
int tot = j + a[i-j];
if(i-tot < 0) continue;
book[sg[i-tot]] = 1;
}
for(int j = 0; book[j]; j++)
sg[i] = j+1;
}
}
int main()
{
int p;
while(~scanf("%d%d", &p, &k))
{
int ans = 0;
while(p--)
{
int n;
scanf("%d", &n);
memset(sg, 0, sizeof(sg));
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
get_sg(n);
ans ^= sg
;
}
if(ans) printf("Alice can win.\n");
else printf("Bob will win.\n");
}
return 0;
}
相关文章推荐
- UVALive 7278 Game of Cards (sg函数)
- UVALive-7278 - Game of Cards
- UVALive-7278 - Game of Cards【博弈】【sg定理】
- UVALive 7278 Game of Cards
- UVa Live 7278 - Game of Cards 博弈
- LA 7278 Game of Cards(SG函数)
- [nim博弈扩展 sg函数] UVALive 3668 A Funny Stone Game
- 【UVALive 7505】Hungry Game of Ants(DP)
- The Same Game UVA 758/Uvalive 5423 大模拟 求最大联通块并清除
- Uva 10891 Game of Sum(区间DP)
- UVA 10891 Game of Sum(区间DP)
- uva10891 Game of Sum
- UVa 1378 A Funny Stone Game [博弈论 SG函数]
- UVALive 6342 The Mirror of Galadriel (回文串)
- UVA 10891 Game of Sum
- UVa10891 Game of Sum(dp)
- UVALive-3523 Knights of the Round Table (双连通分量+二分图匹配)
- uva live 12846 A Daisy Puzzle Game
- Game of Hyper Knights (SG函数)
- UVALive3415[Guardian of Decency] 二分图最大独立集模型