UVALive 7278 Game of Cards
2016-08-14 10:03
435 查看
题目链接: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 100000007
const 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
;
}
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;
}
题意:有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 100000007
const 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
;
}
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;
}
相关文章推荐
- UVALive-7278 - Game of Cards
- UVALive-7278 - Game of Cards【博弈】【sg定理】
- UVa Live 7278 - Game of Cards 博弈
- UVALive-7278 - Game of Cards(sg函数)
- UVALive 7278 Game of Cards (sg函数)
- LA 7278 Game of Cards(SG函数)
- 【UVALive 7505】Hungry Game of Ants(DP)
- codeforces 777 BGame of Credit Cards(贪心)
- Uva 10891 - Game of Sum ( 区间dp )
- UVA10891[Game of Sum] 动态规划
- UVA 10891 Game of Sum
- UVA 10891 Game of Sum(区间DP)
- UVA - 10891 —— Game of Sum
- UVALive 3523 Knights of the Round Table(二分图+双连通分量)
- UVAlive3523 Knights of the Round Table(bcc)
- UVALive 6919 A game for kids(树形dp)
- UVa 10891 - Game of Sum
- UVA - 10891 Game of Sum(区间dp)
- uva 10891 - Game of Sum
- UVA10891 Game of Sum