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 ...
随机推荐
- JMeter一台机器可以支持多大的并发量
Support for concurrent thread is basically depends on many factors like OS, free RAM and connections ...
- Effective.Java第56-66条(规范相关)
56. 为所有已公开的API元素编写文档注释 要正确地记录API,必须在每个导出的类.接口.构造方法.方法和属性声明之前加上文档注释.如果一个类是可序列化的,还需要记录它的序列化形式. 文档注释在源 ...
- npm install 报错 error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,"d' 解决办法
npm install 报错 : error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,& ...
- play framework + sbt入门之环境搭建
一 sbt的使用 SBT = (not so) Simple Build Tool,是scala的构建工具,与java的maven地位相同.其设计宗旨是让简单的项目可以简单的配置,而复杂的项目可以复杂 ...
- python面试题_01
前言 现在面试测试岗位,一般会要求熟悉一门语言(python/java),为了考验求职者的基本功,一般会出2个笔试题,这些题目一般不难,主要考察基本功.要是给你一台电脑,在编辑器里面边写边调试,没多大 ...
- Redis 获取和设置密码
1.config get reuqirepass //获取当前密码 2.config set requirepass "password"//设置当前密码,双引号里面为密码
- C#读写调整设置UVC摄像头画面-亮度
有时,我们需要在C#代码中对摄像头的亮度进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄像 ...
- Throwable中几个常见方法。
getMessage();//获取异常信息,返回字符串.例如: toString();//获取异常类名和异常信息,返回字符串.例如: printStackTrace();//获取异常类名和异常信息,以 ...
- Java自学-类和对象 包
Java中的 包 包: package 把比较接近的类,规划在同一个包下 步骤 1 : 把比较接近的类,规划在同一个包下 Hero,ADHero 规划在一个包,叫做charactor(角色) Item ...
- Scheduling Tasks
官方文档 https://spring.io/guides/gs/scheduling-tasks/ 官方文档详细介绍了@Scheduled中fixedRate,fixedDelay,cron的用法 ...