题目:http://acm.hdu.edu.cn/showproblem.php?pid=1729

思路:理解错题目了,以为SG模板直接套就行了。后来队友说了那个ci是不断变化的。那么每次可以放的石头数量也是不断变化的。但是按照自己的思路改了改模板,(TLE),最后看了题解理解了一下。

看了网上好多题解,有一点想法了:题解都是找到一个q,使得

q+q*q < si && (q+1) + (q+1)*(q+1) >= si --------------------------------------------------(****)

如果 ci > q, 先收获胜 返回si - ci。如果ci < q, 则递归SG(q, ci),

为什么找这样的q呢?为什么这样判断呢?

倒着推理,假如我玩这个游戏,我先找到q,使得(****)成立,然后判断ci和q的关系

如果q < ci, 也就是 ci >= (q+1), 那么我就能放满,先手获胜 返回si-ci 。因为GS(si,si) = 0,(空间size大小为S,begin为S,谁都不能放,先手败)必败状态,GS(si, si-1)的后继只有GS(si, si) ,所以GS(si, si-1) = 1, 同理 GS(si, si-2) = 2 , GS(si, ci) = si - ci;

如果q = ci, 肯定是必败的。我这次放不满,但是下次的肯定能放满(注意(***)

如果ci < q, 不能确定状态,所以要递归SG(q, ci)。

多想想应该就理解了

AC代码:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define in freopen("in.txt", "r", stdin);
typedef long long ll;
const int inf = 0x3f3f3f3f; int SG(int si, int ci) {
int q = sqrt((double) si);
while(q+q*q >= si) q--;//找到刚好使 q+q*q < si && (q+1)+(q+1)*(q+1) >= si
if(ci > q) // 先手获胜
return si - ci;
else //无法判断,递归
return SG(q, ci);
} int main() {
//in;
int n, si, ci;
int j = 1;
while(~scanf("%d", &n) && n) {
int sum = 0;
while(n--) {
scanf("%d %d", &si, &ci);
sum ^= SG(si, ci);
}
printf("Case %d:\n", j++);
if(sum)//原来这里写反了 很郁闷
printf("Yes\n");
else
printf("No\n");
}
}

HDU1729 Stone Game的更多相关文章

  1. POJ1740A New Stone Game[组合游戏]

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5769   Accepted: 3158 ...

  2. timus 1180. Stone Game 解题报告

    1.题目: 1180. Stone Game Time limit: 1.0 secondMemory limit: 64 MB Two Nikifors play a funny game. The ...

  3. HDU 4048 Zhuge Liang's Stone Sentinel Maze

    Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/327 ...

  4. POJ 1740 A New Stone Game

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5453   Accepted: 2989 ...

  5. Light OJ 1296 - Again Stone Game (博弈sg函数递推)

    F - Again Stone Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  6. poj 1115 Lifting the Stone 计算多边形的中心

    Lifting the Stone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. 【POJ】A New Stone Game(博弈论)

    http://poj.org/problem?id=1740 题目大意就是,对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分 ...

  8. HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

    A simple stone game                                                                                  ...

  9. POJ 1740 A New Stone Game(普通博弈)

    A New Stone Game 题意: 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输 ...

随机推荐

  1. linux命令学习笔记(17):whereis 命令

    whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和 源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度 ...

  2. Java中的参数传值方式

    本文转载自 https://blog.csdn.net/SEU_Calvin/article/details/70089977 1.  你觉得下面程序会输出什么 public static void  ...

  3. 关于对H264码流的TS的封装的相关代码实现

    1 写在开始之前 在前段时间有分享一个H264封装ps流到相关文章的,这次和大家分享下将H264封装成TS流到相关实现,其实也是工作工作需要.依照上篇一样,分段说明每个数据头的封装情况,当然,一样也会 ...

  4. LiveMediaStreamer

    LiveMediaStreamer is an open source multimedia framework that allows the manipulation of multiple au ...

  5. HDU5768Lucky7(中国剩余定理+容斥定理)(区间个数统计)

    When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortun ...

  6. ACM学习历程—HDU4675 GCD of Sequence(莫比乌斯)

    Description Alice is playing a game with Bob. Alice shows N integers a 1, a 2, …, a N, and M, K. She ...

  7. 立方体贴图(Cubemap)

    http://blog.csdn.net/asdjy123/article/details/51190643 点击打开链接 好东西保存方便查看 立方体贴图(Cubemap) 原文 Cubemaps 作 ...

  8. npm in macbook

    打开终端,试了很多次 npm install anywhere -g,结果还是报错,大概就说没权限. 所以,才想起之前看过的博客中,提到用sudo去执行. 终于,没问题了! 如果npm install ...

  9. MYSQL主从复制配置遇到的问题

    在进行配置从服务器时遇到的错误. mysql> change master to master_host='192.168.136.129',master_user='repl',master_ ...

  10. VS2008中宽字节和普通字节的使用

    由于麻烦,所以并没有使用宽字节,留待以后.