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. 【Linux】CentOS7 打开关闭防火墙及端口

    一.centos7版本对防火墙进行加强,不再使用原来的iptables,启用firewalld1.firewalld的基本使用启动: systemctl start firewalld查状态:syst ...

  2. java中Math类

    Math类 Math类是一个很有用的数学帮助类,使用也非常简单,这个类比较特殊,首先他和String类一样都是用final修饰,所以不能有子类,还有就是它的构造方法是私有的,也就是我们不能通过new的 ...

  3. 调用WebApi出现 远程服务器返回错误: (500) 内部服务器错误

    一.检查错误错误 将 HttpWebResponse response = (HttpWebResponse)request.GetResponse();改为 HttpWebResponse resp ...

  4. mybatis使用用stdout-logging日志显示sql语句

    在开发中,我们很多时候需要知道当前执行的sql语句是什么样的,但是默认mybatis是不显示sql的,此时我们就可以使用stdout-logging了.1.创建mybatis-config.xml文件 ...

  5. html5单词

    < meta   charset = " UTF-8 " >         国内编码     (meta-标签用来描述一个HTML网页文档的属性  charset-字 ...

  6. jQuery中的DOM操作(三)

    一.查找节点    [返回jQuery对象]$(选择器字符串);    使用jQuery函数,里面参数为选择器字符串,查询符合条件的BOM对象并返回jQuery对象eg: $('div.one spa ...

  7. Vue学习之品牌案例部分代码小结(二)

    品牌案例的增删查和其他部分效果: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  8. Android-----RadioButton单选使用(实现简单温度转换)

    废话少说,直接上代码: xml布局文件代码: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  9. elasticsearch Terms Query 实现类似于sql in查询

    本文demo基于elasticsearch 5.1.1,  项目中使用的还是较早的版本 例如 import com.alibaba.fastjson.JSON; import org.elastics ...

  10. MySQL MHA--主库故障检测

    MHA主库检查参数 MHA从0.53版本开始支持ping_type参数来设置如何检查master可用性:ping_type=select: 基于一个到master的已经存在的连接执行select 1, ...