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. iOS中归档对象的创建,数据写入与读取

    归档(archiving)是指另一种形式的序列化,但它是任何对象都可以实现的更常规的模型.专门编写用于保存数据的任何模型对象都应该支持归档.比属性列表多了很良好的伸缩性,因为无论添加多少对象,将这些对 ...

  2. <实训|第四天>Linux下的vim你真的掌握了吗?附上ftp远程命令上传。

    期待已久的linux运维.oracle"培训班"终于开班了,我从已经开始长期四个半月的linux运维.oracle培训,每天白天我会好好学习,晚上回来我会努力更新教程,包括今天学到 ...

  3. WCF Data Service 使用小结(二) —— 使用WCF Data Service 创建OData服务

    在 上一章 中,介绍了如何通过 OData 协议来访问 OData 服务提供的资源.下面来介绍如何创建一个 OData 服务.在这篇文章中,主要说明在.NET的环境下,如何使用 WCF Data Se ...

  4. 关于hangfire的使用

    hangfire 是一个分布式后台执行服务.用它可以代替ThreadPool.QueunItemWork等原生方法.当然4.5后的 task也是相当好用且功能强大.不过如果想分布式处理并且可监控的话, ...

  5. mac点滴

    1.8个常用的功能. 转载:http://www.tuicool.com/articles/BfEjQzr 2.把pwd复制到剪切板?  pwd  |  pbcopy 有时间看看这个 http://j ...

  6. Boostrap响应式与非响应式

    非响应式布局 在使用非响应式布局时,在<head>标签中需要加入一下内容,其中最主要的是non-responsive.css文件 <head> <meta http-eq ...

  7. [C#基础]说说委托+=和-=的那些事

    写在前面 为什么会突然想说说委托?原因吗,起于一个同事的想法,昨天下班的路上一直在想这个问题,如果给委托注册多个方法,会不会都执行呢?为了一探究性,就弄了个demo研究下. += 大家都知道委托都继承 ...

  8. [工具类]文件或文件夹xx已存在,则重命名为xx(n)

    写在前面 最近在弄一个文件传输的一个东东,在接收文件的时候,如果文件已经存在,该如何处理?提示?删除?感觉直接删除实在不太合适,万一这个文件对用户来说很重要,你给他删除了肯定不行.然后就想到了,win ...

  9. MyEclipse8.5快速搭建SSH框架

    来源于:http://jingyan.baidu.com/article/a378c960a78125b3282830cc.html MyEclipse8.5快速搭建SSH框架 使用版本: Strut ...

  10. 如何解决mysql数据库X小时无连接自动关闭

    windows下打开my.ini,增加: interactive_timeout=28800000 wait_timeout=28800000 专家解答:MySQL是一个小型关系型数据库管理系统,由于 ...