题意:

在经典Nim博弈的基础上增加了新的限制:如果从这堆石子中移走\(x\)个石子,那么之后就不能再从这堆移走\(x\)个。

分析:

因为之前的操作会对后面的转移有影响,所以在保存状态时还要记录哪些数量的石子可以移走。

\(d(i,S)\)表示现在有\(i\)个石子,\(S\)中\(1\)的位置表示可以移走对应数量的石子,打表求出\(SG\)函数值。

打表代码:

#include <cstdio>
#include <cstring> bool vis[100]; int mex() {
for(int i = 0; ; i++) if(!vis[i]) return i;
} int sg[11][1 << 10]; int main()
{
memset(sg, -1, sizeof(sg));
for(int i = 0; i < (1 << 10); i++) sg[0][i] = 0;
for(int i = 1; i <= 10; i++) {
sg[i][0] = 0;
for(int j = 1; j < (1 << 10); j++) {
memset(vis, false, sizeof(vis));
for(int k = 0; k < i; k++) if((j >> k) & 1)
vis[sg[i - k - 1][j ^ (1 << k)]] = true;
sg[i][j] = mex();
}
} for(int i = 0; i <= 10; i++)
printf("i = %d: sg = %d\n", i, sg[i][(1 << i) - 1]); return 0;
}

找到规律后就把问题解决了。

#include <cstdio>

int sg[61];

int main()
{
for(int i = 1, p = 1; p <= 60; i++) {
for(int j = 0; j < i + 1 && p <= 60; j++) {
sg[p++] = i;
}
} int ans = 0;
int n; scanf("%d", &n);
while(n--) { int x; scanf("%d", &x); ans ^= sg[x]; }
if(ans) printf("NO\n"); else printf("YES\n"); return 0;
}

CodeForces 768E Game of Stones 打表找规律的更多相关文章

  1. Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)

    题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...

  2. Codeforces 193E - Fibonacci Number(打表找规律+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... ...

  3. Codeforces 998D. Roman Digits 【打表找规律】

    <题目链接> 题目大意: 现在有无限个 1,5,10,50这四个数字,从中恰好挑选n个数字,问你这些数字的和总共有多少种不同的情况. 解题分析: 由于此题 n 的范围特别大,达到了1e9, ...

  4. Codeforces 456B Fedya and Maths 打表找规律

    Description Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expre ...

  5. codeforces#1090 D. New Year and the Permutation Concatenation(打表找规律)

    题意:给出一个n,生成n的所有全排列,将他们按顺序前后拼接在一起组成一个新的序列,问有多少个长度为n的连续的子序列和为(n+1)*n/2 题解:由于只有一个输入,第一感觉就是打表找规律,虽然表打出来了 ...

  6. Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

    D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Beta Round #24 D. Broken robot (打表找规律)

    题目链接: 点击我打开链接 题目大意: 给你 \(n,j\),再给出 \(m[0]\) 的坐标和\(a[0]-a[n-1]\) 的坐标. 让你输出 \(m[j]\) 的坐标,其中 \(m[i]\) 和 ...

  8. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  9. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

随机推荐

  1. Crash日志分析

    从Crash文件出发解决bug的一般步骤,分三步: a, 获取设备上的崩溃日志. b, 分析崩溃日志,找到报错位置(定位到函数和代码行数). c, 打开代码,改bug. 1, 获取设备日志 1. 在可 ...

  2. 解决在eclipse中导入项目名称已存在的有关问题

    新建项目-Import-File System-找到相应的文件夹-Overwrite existing resources without warning打钩,选中项目即可

  3. Day5 CSS基本样式和C3选择器

    Day5 CSS基本样式和C3选择器 一.背景属性 1.背景颜色            background-color:transparent(默认值,透明); 颜色的取值:            ...

  4. PHP报错configure error Cannot find libmysqlclient under usr

    编译PHP报错configure error Cannot find libmysqlclient under usr的解决方法 (问题产生,mysql是yum安装的,libmysqlclient* ...

  5. 使用Loadrunner监控Windows资源

    为了区分把装有loadrunner的机器称作A,被监控资源的服务器(windows)称作B 1.确保B机器Administrator账户是可使用状态:右键计算机→ 管理→ 本地用户和组→ 用户,其中A ...

  6. thinkphp分页+条件查询

    最近项目上面有一个带条件查询的分页列表,一开始form用的post,点击第二页就没有跳转成功,原因是分页是get请求,post数据链接到其他页面就会被清除. 解决办法: 1.form表单method= ...

  7. LeetCode Valid Parentheses 有效括号

    class Solution { public: void push(char c){ //插入结点 struct node *n=new struct node; n->nex=; n-> ...

  8. 多进程——waitpid()函数的小例子

    本例中使用fork()创建一个子进程,然后让子进程暂停5s,接下来对原有的父进程使用waitpid()函数,利用WNOHANG使父进程不会阻塞每隔一秒判断子进程是否退出. #include" ...

  9. MySQL binlog server

    从5.6版本开始,可以利用 mysqlbinlog命令把远程机器的日志备份到本地目录,这样就更加方便快捷的实现一个binlog server. 环境介绍:192.168.56.100是备份服务器,19 ...

  10. 【洛谷2257】YY的GCD(莫比乌斯反演)

    点此看题面 大致题意: 求\(\sum_{x=1}^N\sum_{y=1}^MIsPrime(gcd(x,y))\). 莫比乌斯反演 听说此题是莫比乌斯反演入门题? 一些定义 首先,我们可以定义\(f ...