Crosses and Crosses
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 3063   Accepted: 1196
Case Time Limit: 2000MS

Description

The game of Crosses and Crosses is played on the field of 1 × n cells. Two players make moves in turn. Each move the player selects any free cell on the field and puts a cross ‘×’ to it. If after the player’s move there are three crosses in a row, he wins.

You are given n. Find out who wins if both players play optimally.

Input

Input file contains one integer number n (3 ≤ n ≤ 2000).

Output

Output ‘1’ if the first player wins, or ‘2’ if the second player does.

Sample Input

#1 3
#2 6

Sample Output

#1 1
#2 2

Source

Northeastern Europe 2007, Northern Subregion

【思路】

SG函数,博弈

题目treblecross的简化。

【代码】

 #include<cstdio>
#include<cstring>
using namespace std; const int N = +; int sg[N],n; int dfs(int x) {
if(x<=) return ;
if(sg[x]!=-) return sg[x];
int vis[N];
memset(vis,,sizeof(vis));
for(int i=;i<=x;i++)
vis[dfs(i-)^dfs(x-i-)]=;
for(int i=;;i++)
if(!vis[i]) return sg[x]=i;
} int main() {
memset(sg,-,sizeof(sg));
while(scanf("%d",&n)==) {
if(dfs(n)) puts("");
else puts("");
}
return ;
}

poj 3575 Crosses and Crosses(SG函数)的更多相关文章

  1. POJ 2311 Cutting Game(SG函数)

    Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4806   Accepted: 1760 Desc ...

  2. POJ 2960 S-Nim 博弈论 sg函数

    http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...

  3. POJ 3537 Crosses and Crosses(sg博弈)

    题目:在1*n 的棋盘里面,A和B都在里面画叉 , 如果谁可以画了一个叉后,可以连成3个叉,那谁胜利 : 分析: 首先考虑如果我在玩游戏,我最希望对手可以画出-x-x or  -xx-   ,  这种 ...

  4. POJ 3537 Crosses and Crosses (NEERC)

                      Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4 ...

  5. POJ 3537 Crosses and Crosses

    Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2237 Accepted: 821 Ca ...

  6. 【POJ】【3537】Crosses and Crosses

    博弈论 相当于放了x的位置,左右4格都不能再放x了,谁无处可放就输. n<=2000 直接枚举后继状态,暴力求SG函数即可. 例: 0000000->x..0000 / .x..000 / ...

  7. POJ 2425 A Chess Game 博弈论 sg函数

    http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...

  8. POJ 3537:Crosses and Crosses(Multi-Nim)

    [题目链接] http://poj.org/problem?id=3537 [题目大意] 在一个1*n的方格纸上下棋,谁先连三子谁就赢了,问必胜的是谁. [题解] 我们发现对于一个n规模的游戏.在i位 ...

  9. POJ 2960 S-Nim (sg函数)

    题目链接:http://poj.org/problem?id=2960 题目大意:给定数组S,接下来给出m个游戏局面.游戏局面是一些beads堆,先给出堆数,然后是每一堆中beads的数目.游戏规则是 ...

随机推荐

  1. oraclesql日志

    select * from v$logfile;  select * from v$sql select sql_text,module,action,parsing_schema_name,firs ...

  2. iOS,长按图片保存实现方法,轻松搞定!

    1.添加手势识别: UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@s ...

  3. libConfuse的使用

    前言 在软件编程中经常会使用到一些参数,在存储方面一般有使用XML的,也有使用文本文件的,或者使用数据库的等.我们软件平台一些参数是使用XML文件存储,在读取方面的速度还可以,但在写回文件速度一般.也 ...

  4. 《paste命令》-linux命令五分钟系列之二十

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  5. Asp.net服务器控件在IE10下的不兼容问题

    Asp.net服务器控件在IE10下的不兼容问题 时间:2013-05-16 09:07点击: 89 次 [大 中 小] 相信很多使用IE10的童鞋们已经发现了这个问题,以下是本人在IE10标准模式下 ...

  6. phpmyadmin数据导入最大限制的解决方法

    mysql导入文件最大限制更改解决方法:phpmyadmin库导入出错:You probably tried to upload too large file. Please refer to doc ...

  7. jquery获取css color 值返回RGB

    css代码如下: a, a:link, a:visited { color:#4188FB; } a:active, a:focus, a:hover { color:#FFCC00; } js代码如 ...

  8. 指令发email

    win7下指令发送email:(telnet:不为内部指令时控制面板 -> 程序和功能 -> 打开或关闭Windows功能,如下“telnet客户端”) telnet smtp.sina. ...

  9. linux下安装busybox

    1.获取busybox源码并解压,这里使用天嵌提供的“busybox-1.16.0.tar.bz2” #tar xvf busybox-.tar.bz2 -C / 解压的目的地址实际上是:/opt/E ...

  10. 微信JS-SDK签名signature错误代码4029

    一般是url的错,url需要动态获取 c#的写法: //Request.Url.ToString()这个获取的是没有端口号的有些网站有端口号 string url = Request.Url.Orig ...