题目: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. codeforces 652D D. Nested Segments(离散化+sort+树状数组)

    题目链接: D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. 《java编程思想》:散列的原理

    以实现一个简单的HashMap为例,详细讲解在code之中. 简单解释散列原理: 1.map中内建固定大小数组,但是数组并不保存key值本身,而是保存标识key的信息 2.通过key生成数组角标,对应 ...

  3. php断点续传

    http://www.cnblogs.com/xproer/archive/2012/10/26/2741264.html

  4. Asp.Net页面生命周期【转载,地址:http://www.cnblogs.com/xhwy/archive/2012/05/20/2510178.html】

    一.什么是Asp.Net页面生命周期 当我们在浏览器地址栏中输入网址,回车查看页面时,这时会向服务器端(IIS)发送一个request请求,服务器就会判断发送过来的请求页面,  完全识别 HTTP 页 ...

  5. 每天一个linux命令(6):rm命令

    版权声明更新:2017-05-10博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1文章介绍 本文介绍了Linux下面的rm命令. 2 开 ...

  6. BZOJ2212:[POI2011]Tree Rotation

    浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...

  7. POJ3256:Cow Picnic

    Cow Picnic Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5432   Accepted: 2243 Descri ...

  8. HDUj2612(两个起点找到最近的目的地)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. VisualGDB系列9:配置VS直接通过SSH方式访问Linux项目

    根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何使用VS和VisualGDB ...

  10. WCF服务用户名密码访问

    有2种方式, 第一直接在程序中指定用户名密码,配置调用 private void BtnSearch_Click(object sender, EventArgs e) { try { var cli ...