Game of Cards Gym - 101128G (SG函数)
Problem G: Game of Cards
\]
题意
题意就是给出\(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函数)的更多相关文章
- UVALive 7278 Game of Cards (sg函数)
Game of Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/G Description Alice and Bob ...
- LA 7278 Game of Cards(SG函数)
https://vjudge.net/problem/UVALive-7278 题意: 两个人玩游戏,现在有n堆牌,轮到自己时,先在牌堆中选一堆牌,先在牌堆中选择拿走0~k张牌(至少得剩下一张),然后 ...
- 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho
以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; i ...
- codeforce Gym 100500E IBM Chill Zone (SG函数)
关于sg函数这篇blog讲得很详细http://blog.csdn.net/logic_nut/article/details/4711489. sg函数的价值在于把复杂的游戏拆分成简单的游戏,然后通 ...
- gym/102059/problem/I. Game on Plane SG函数做博弈
传送门: 题意: 给定一个正n边形的点.双方轮流连点成线,要求所画的线不能与之前的线相交.当某个人连成一个回路,这个人就输了.问先手必胜还是后手必胜. 思路: SG函数,因为一条线相当于把图劈成了两半 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
- 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)运算 ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
随机推荐
- 『炸弹 线段树优化建图 Tarjan』
炸弹(SNOI2017) Description 在一条直线上有 N 个炸弹,每个炸弹的坐标是 Xi,爆炸半径是 Ri,当一个炸弹爆炸 时,如果另一个炸弹所在位置 Xj 满足: Xi−Ri≤Xj≤Xi ...
- GoF的23种设计模式之行为型模式的特点和分类(1)
行为型模式用于描述程序在运行时复杂的流程控制,即描述多个类或对象之间怎样相互协作共同完成单个对象都无法单独完成的任务,它涉及算法与对象间职责的分配. 行为型模式分为类行为模式和对象行为模式,前者采用继 ...
- winform datagridview控件使用
最近做项目时,显示查询结果总需要绑定到datagridview控件上显示,总结了给datagridview绑定数据的方式,以及导出datagridview数据到excel表格,如有错误请多指教 1.直 ...
- 解决微信web页面键盘收起不回弹,导致按钮失效
在文本框失去焦点时加入以下代码 $('input,textarea').blur(function () { setTimeout(function(){ window.scrollTo(,docum ...
- python卸载重新安装,一键安装卸载前的所有安装的第三方插件
好多小可爱都有这样一个困扰,python有了一个大版本的更新,我也想更新,但是安装的好多第三方的库可怎么办呀,更新之后再去一个一个的安装,那可就烦死了. 在这里我来教大家如何快速去安装python更新 ...
- Mybatis 映射器接口实现类的方式 运行过程debug分析
查询一张表的所有数据. 环境: 使用工具IntelliJ IDEA 2018.2版本. 创建Maven工程不用骨架 <?xml version="1.0" encoding= ...
- Python pip安装第三方库的国内镜像
Windows系统下,一般情况下使用pip在DOS界面安装python第三方库时,经常会遇到超时的问题,导致第三方库无法顺利安装,此时就需要国内镜像源的帮助了. 使用方法如下: 例如:pip inst ...
- 剑指前端(前端入门笔记系列)——Math对象
Math对象 ECMAScript将一些常用的数学公式和信息封装到了一个对象中——Math对象,为我们实现数学方面的计算功能提供了便捷,而且该对象还提供了辅助完成这些计算的属性和方法 属性 con ...
- AMD规范中模块id的命名规则
AMD 即 Asynchronous Module Definition, 中文是“ 异步模块定义”的意思. AMD 规范制定了定义模块的规则,这样模块和模块的依赖可以被异步加载. AMD 规范只定义 ...
- 面试题:什么叫B树
B是balanced的意思 是在二叉查找树 树的基础上增加了平衡的性质 导致它不是 二叉树了,变成了多叉树,但是叉几路又有了限制 否则怎么平衡呢 一棵m阶B树(balanced tree o ...