题目: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. BEC listen and translation exercise 31

    听力练习: All societies have ways of encouraging and enforcing what they view as appropriate behaviour w ...

  2. png8 png24 png32

    解释 PNG8 : 8位的PNG最多支持256(2的8次方)种颜色,8位的PNG支持不透明.索引透明.alpha透明. PNG24 : 支持2的24次方种颜色,表现为不透明.PS导出PNG24是会根据 ...

  3. poj-1379 Run Away(模拟退火算法)

    题目链接: Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7982   Accepted: 2391 De ...

  4. PS 滤镜— —挤压效果

    clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...

  5. oracle数据库规划建议

    之前负责的项目有用到oracle的,oracle dba给过一些建议,自己整理了一下,写再这里做个备忘 数据库需求分析: 1. 创建的数据库名称为maildb,并且字符集为UTF8. 2. 提供可连接 ...

  6. HDOJ1242(延时迷宫BFS+优先队列)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. Python:模块详解及import本质

    转于:http://www.cnblogs.com/itfat/p/7481972.html 博主:东大网管 一.定义: 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能), ...

  8. JVM体系结构之三:方法区之1

    一.简介 方法区在JVM中也是一个非常重要的区域,它与堆一样,是被线程共享的区域.在方法区中,存储了每个类的信息(包括类的名称.方法信息.字段信息).静态变量.常量以及编译器编译后的代码等. 方法区( ...

  9. telnet IP:ERROR

    实验环境:CentOS6.8 主机:172.16.xxx.xxx:80 客户端:172.16.xxx.xxx [root@www ~18:32:27]#telnet 172.16.xxx.xxx 80 ...

  10. Python模块-requests(一)

    requests不是python自带的,使用前需要安装 发送请求 HTTP请求类型有GET,POST,PUT,DELETE,HEAD和OPTIONS 使用requests发送请求的方法如下: > ...