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. Eclipse出现the type java.lang.CharSequence can't be resolved.

    出现这个问题我们需要安装一下JRE1.7这个版本,然后再项目里引入一下就可以了.

  2. virtualbox共享文件夹无访问权限问题解决方法

    virtualbox共享文件夹无访问权限问题解决方法 早就困扰了,这次新装虚拟机又碰到了,记录下来. 这篇文章主要介绍了virtualbox共享文件夹无访问权限问题解决方法,造成这个问题的原因是不跟v ...

  3. MySQL execute dynamic sql script.

    SET @sql = (SELECT IF( (SELECT COUNT(*) FROM usher_network_log ) > 1000000, "SELECT 0", ...

  4. List集合的去除重复性练习

    package com.java.b.listdmeo.www; import java.util.ArrayList;import java.util.Iterator; import com.ja ...

  5. 【转】NHibernate入门教程

    开源框架完美组合之Spring.NET + NHibernate + ASP.NET MVC + jQuery + easyUI 中英文双语言小型企业网站Demo 摘要: 热衷于开源框架探索的我发现A ...

  6. 【BZOJ3456】【CDQ分治+FNT】城市规划

    试题来源 2013中国国家集训队第二次作业 问题描述 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得 ...

  7. 《Velocity 模板使用指南》中文版[转]

    转自:http://blog.csdn.net/javafound/archive/2007/05/14/1607931.aspx <Velocity 模板使用指南>中文版 源文见 htt ...

  8. php 目录及文件操作

    // bool is_dir(string $filename) 判断给定文件名是否是一个目录.// resource opendir(string $path[,resource $context] ...

  9. python中的字典应用实例

    字典中的键使用时必须满足一下两个条件: 1.每个键只能对应一个项,也就是说,一键对应多个值时不允许的(列表.元组和其他字典的容器对象除外).当有键发生冲突时(即字典键重复赋值),取最后的赋值. > ...

  10. Cinder-2 窗口的创建过程

    通过TinderBox生成的代码很简单,整个代码如下: #include "cinder/app/AppNative.h" #include "cinder/gl/gl. ...