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

6

Sample Output
2

Source

Northeastern Europe 2007, Northern Subregion
 
 
/*
因为只要有三个X连起来就赢了,所以肯定不能在X旁边或者旁边的旁边放,不然下一步对手就赢了。
所以放X就相当于把序列分割成 1/2 块。
sg(x)表示长度为x且两端 不能放的SG函数
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define ll long long
#define maxn 2005
using namespace std;
int sg[maxn],n,m;
int v[maxn*];
inline void init(){
sg[]=sg[]=sg[]=;
sg[]=sg[]=sg[]=; int now,x,y;
for(int i=;i<=;i++){
v[sg[i-]]=i;
x=,y=i-;
while(x<=y){
v[sg[x]^sg[y]]=i;
x++,y--;
} now=;
while(v[now]==i) now++;
sg[i]=now;
}
} int main(){
init();
// for(int i=1;i<=20;i++) printf("%d %d\n",i,sg[i]);
while(scanf("%d",&n)==){
if(sg[n+]) puts("");
else puts("");
}
return ;
}

POJ 3537 Crosses and Crosses (NEERC)的更多相关文章

  1. POJ 3537 Crosses and Crosses

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

  2. 【POJ】【3537】Crosses and Crosses

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

  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. [模拟赛] StopAllSounds

    Description 小松鼠开心地在树之间跳跃着,突然她停了下来.因为眼前出现了一个 拿着专克超萌小松鼠的法宝----超萌游戏机的游客! 超萌游戏机之所以拥有这个名字,是因为它的屏幕是一个n × 2 ...

  2. LwIP - 打开keepalive功能

    在服务器端打开keepalive功能 1.保证LWIP_TCP_KEEPALIVE被定义为1,(这样TCP_KEEPIDLE.TCP_KEEPINTVL和TCP_KEEPCNT 设置才有效) 2. i ...

  3. Out of memory due to hash maps used in map-side aggregation解决办法

    在运行一个group by的sql时,抛出以下错误信息: Task with the most failures(4): -----Task ID:  task_201411191723_723592 ...

  4. Java面向对象编程三大特性 --- 多态

    多态特性: 子类Child继承父类Father,我们可以编写一个指向子类的父类类型引用,该引用既可以处理父类Father对象,也可以处理子类Child对象,当相同的消息发送给子类或者父类对象时,该对象 ...

  5. 教主泡嫦娥(RQNOJ 595)

    题目描述 [问题背景] 2012年12月21日下午3点14分35秒,全世界各国的总统以及领导人都已经汇聚在中国的方舟上. 但也有很多百姓平民想搭乘方舟,毕竟他们不想就这么离开世界,所以他们决定要么登上 ...

  6. 【STSRM13】木之本樱

    [题意]抽象模型后转化为:给定n个直线,ans+=C(x,4)*8,x为每个经过直线数>=4的点的直线数,不存在平行直线. [算法]数学 [题解] 运用了一个很简单的道理:经过同一个点的线段互相 ...

  7. [bzoj2599][IOI2011]Race——点分治

    Brief Description 给定一棵带权树,你需要找到一个点对,他们之间的距离为k,且路径中间的边的个数最少. Algorithm Analyse 我们考虑点分治. 对于子树,我们递归处理,所 ...

  8. csrf_execmp

    参考;https://www.cnblogs.com/zhaof/p/6281482.html 全局: 中间件 django.middleware.csrf.CsrfViewMiddleware 局部 ...

  9. shell脚本之正则表达和文本处理(文本处理三剑客:1、grep 2、sed 3、awk)

    文本处理三剑客:1.grep  2.sed  3.awk 一.grep:(过滤) grep的使用,主要的参数有: -n  :显示行号:-o  :只显示匹配的内容-q  :静默模式,没有任何输出,得用e ...

  10. POJ2479(最长连续子序列和)

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37035   Accepted: 11551 Des ...