Problem G: Game of Cards

\[Time Limit: 1 s \quad Memory Limit: 256 MiB
\]

题意

题意就是给出\(n\)堆扑克牌,然后给出一个\(m\),每次一个人的操作方法是从一堆扑克牌上面选出\(0-m\)张牌拿开,然后此时顶上牌的点数是\(x\),在拿开\(x\)张牌,最后不能操作的人输。

思路

就是一个裸的\(sg\)函数,用dfs比较好写,然后直接模拟就可以了。

/***************************************************************
> File Name : G.cpp
> Author : Jiaaaaaaaqi
> Created Time : 2019年05月06日 星期一 18时04分27秒
***************************************************************/ #include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
#define INOPEN freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e3 + 10;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std; int n, m, k;
int cas, tol, T; int a[maxn];
ll sg[maxn]; void dfs(int x) {
if(sg[x] != -1) return ;
vector<bool> vis(maxn, false);
for(int i=0; i<=m; i++) {
int up = x-i;
if(up <= 0) break;
int nxt = up - a[up];
if(nxt < 0) continue;
dfs(nxt);
vis[sg[nxt]] = true;
}
for(int i=0; ; i++) {
if(!vis[i]) {
sg[x] = i;
return ;
}
}
} int main() {
scanf("%d%d", &T, &m);
ll ans = 0;
while(T--) {
scanf("%d", &n);
mes(a, 0);
mes(sg, -1);
a[0] = sg[0] = 0;
for(int i=1; i<=n; i++) {
scanf("%d", &a[i]);
}
dfs(n);
ans ^= sg[n];
}
if(ans)
printf("Alice can win.\n");
else
printf("Bob will win.\n");
return 0;
}

Game of Cards Gym - 101128G (SG函数)的更多相关文章

  1. UVALive 7278 Game of Cards (sg函数)

    Game of Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/G Description Alice and Bob ...

  2. LA 7278 Game of Cards(SG函数)

    https://vjudge.net/problem/UVALive-7278 题意: 两个人玩游戏,现在有n堆牌,轮到自己时,先在牌堆中选一堆牌,先在牌堆中选择拿走0~k张牌(至少得剩下一张),然后 ...

  3. 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho

    以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; i ...

  4. codeforce Gym 100500E IBM Chill Zone (SG函数)

    关于sg函数这篇blog讲得很详细http://blog.csdn.net/logic_nut/article/details/4711489. sg函数的价值在于把复杂的游戏拆分成简单的游戏,然后通 ...

  5. gym/102059/problem/I. Game on Plane SG函数做博弈

    传送门: 题意: 给定一个正n边形的点.双方轮流连点成线,要求所画的线不能与之前的线相交.当某个人连成一个回路,这个人就输了.问先手必胜还是后手必胜. 思路: SG函数,因为一条线相当于把图劈成了两半 ...

  6. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  7. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

  8. HDU 1848 Fibonacci again and again【SG函数】

    对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...

  9. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

随机推荐

  1. Windows docker k8s asp.net core

    在上一篇文章 Ubuntu 18 Kubernetes的Install and Deploy 我们在ubuntu在部署了k8s集群, 今天来看看windows下怎么搞. 主要点有: 1) window ...

  2. Docker 运行 MySQL,使用 docker-compose

    目录结构 . │ .env │ docker-compose.yml │ └─mysql ├─config │ my.cnf │ └─data mysql 目录下的 data 为数据目录,mysql ...

  3. Redis和数据库一致性

    1.实时同步  对强一致要求比较高的,应采用实时同步方案,即查询缓存查询不到再从DB查询,保存到缓存:      更新缓存时,先更新数据库,再将缓存的设置过期(建议不要去更新缓存内容,直接设置缓存过期 ...

  4. windows如果在IE中用超链接打开谷歌页面

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\openChrome] @="URL:openChrome Protocol& ...

  5. 在微信小程序中使用redux

    本文主要讲述,在微信小程序中如何使用redux DEMO 需要解决的问题 如何在小程序中引入redux状态管理库,及它相关的插件? 微信小程序没有清晰的异步api,便于thunkMiddleware处 ...

  6. 87.CSS Flex 弹性盒模型布局教程(共用的css在48篇文章gird)

    CSS Flex 弹性盒模型布局教程 Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. flex布局就是给任何一个容器添加 dis ...

  7. Java 面向对象(九)内部类

    一.概述 1.引入 类的成员包括: 1.属性:成员变量2.方法:成员方法3.构造器4.代码块5.内部类:成员内部类 其中 1.2是代表这类事物的特征   其中3.4是初始化类和对象用的   其中5协助 ...

  8. Socket-网络服务提供的一种机制

    网络编程 网络通信的要素 Ip,端口,协议(tcp/udp) 127.0.0.1 本机地址   默认主机名:localhost   端口号:用于标识进程的逻辑地址. 有效端口:0-65535   其中 ...

  9. 英语partschinite芬达石partschinite锰铝榴石

    partschinite指锰铝榴石,属于石榴石的一种,由于它有芬达饮料的诱人颜色,大家也称其为“芬达石”.石榴石宝石族中重要品种之一,化学成分为锰铝硅酸盐,颜色从红到橙红,红到棕红,玫瑰红.浅玫红均有 ...

  10. 原油PETROLAEUM英语PETROLAEUM石油

    petrolaeum (uncountable) Archaic spelling of petroleum petroleum See also: Petroleum Contents [hide] ...