Crosses and Crosses
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 2237 Accepted: 821
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

取一个的话周围5个都不能再取了。。。。

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int sg[2200],N;

int SG_dfs(int x)
{
    if(x<=0) return 0;
    if(sg[x]!=-1) return sg[x];
    int i; bool flag[2200];
    memset(flag,false,sizeof(flag));
    for(i=1;i<=x/2+1;i++)
    {
        flag[SG_dfs(i-3)^SG_dfs(x-i-2)]=true;
    }
    for(i=0;i<=x;i++)
        if(!flag) break;
    return sg[x]=i;
}

int main()
{
    memset(sg,-1,sizeof(sg));
    while(scanf("%d",&N)!=EOF)
    {
        printf("%d\n",SG_dfs(N)?1:2);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 3537 Crosses and Crosses的更多相关文章

  1. 【POJ】【3537】Crosses and Crosses

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

  2. POJ 3537 Crosses and Crosses (NEERC)

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

  3. poj 3537 Crosses and Crosses 博弈论之grundy值

    题意: 给1*n的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢.问先手必胜还是必败. 分析: 求状态的grundy值(也就是sg值),详细怎么求详见代码.为什么这么求要自己想的,仅仅可意会(别人都说 ...

  4. poj 3575 Crosses and Crosses(SG函数)

    Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3063   Accepted: 11 ...

  5. POJ 3537 multi-sg 暴力求SG

    长为n的一列格子,轮流放同种棋子,率先使棋子连成3个者胜. 可以发现每次放一个棋子后,后手都不能放在[x-2,x+2]这个区间,那么相当于每次放棋将游戏分成了两个,不能放棋者败. 暴力求SG即可 /* ...

  6. [poj 3537]Crosses and Crosses(博弈论)

    题目:http://poj.org/problem?id=3537 题意:给你n个格子,两个人依次在n个格子的任意空位置画"X",谁如果画了一个后,3个X连在了一起,那么那个人就获 ...

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

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

  8. poj 3537 Crosses and Crosses 博弈论

    思路:每次画X之后都会形成2个子游戏,即i-3和n-i-2. 代码如下: #include<iostream> #include<cstdio> #include<cma ...

  9. POJ 3537 Crosses and Crosses(SG/还未想完全通的一道SG)

    题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; ...

随机推荐

  1. 启动页面设置,icon图标设置

    更多尺寸像素如何放置请看:http://chicun.jammy.cc/ 如何设置App的启动图,也就是Launch Image? 新建一个iosLaunchImage文件夹

  2. http长链接与短链接

    http://www.cnblogs.com/cswuyg/p/3653263.html keep-live模式 这个博客写的很全:http://www.cnblogs.com/skynet/arch ...

  3. ACL权限的学习

    ACL ACL:访问控制列表,其主要作用是将一些"用户"加到表中,并对这些用户的行为进行控制. 案例: 有个文件夹project是root用户创建,并且关于这个文件夹有以下权限 d ...

  4. Unknown column '' in 'field list'解决方案

    很多人在用php+MySQL做网站往数据库插入数据时发现如下错误: 注册失败!Unknown column '1a' in 'field list' 结果发现用数字提交是没有问题的,其他如char型就 ...

  5. java编程

    Java编程:五子棋游戏源代码 import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing ...

  6. 使用Web Deploy进行远程部署

    Web Deploy支持直接从本地Visual Studio的工程文件部署网站到远程服务器,部署的过程中可以对比哪些文件变化了需要拷贝,而不是一股脑的全部拷贝,效率和准确性会更好. 部署的过程主要要注 ...

  7. c语言的数学函数ceil、floor、round

    头文件<math.h> 函数原型和作用 double ceil(double x); 向上取整 double floor(double x); 向下取整 double round(doub ...

  8. Web Api如何传递POST请求

    这里记录一次Web Api传递post请求的例子,由于使用了默认工程的例子,方法名的参数值标记头为FromBody的形式,如下图所示的调用: 调用方式: 那么如果要两个以上的参数如何去实现,这种方式是 ...

  9. Java JDBC下执行SQL的不同方式、参数化预编译防御

    相关学习资料 http://zh.wikipedia.org/wiki/Java数据库连接 http://lavasoft.blog.51cto.com/62575/20588 http://blog ...

  10. c++中string类型用下标初始化后str.size()为0 输出string值为空

    你的string list是个默认构造函数,这样就没有为list分配空间,自然list[i]就会报出超出string范围的错误,可以简单更改为string list(6, '\0'),事先为list指 ...