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. BZOJ2631 tree(伍一鸣) LCT 秘制标记

    这个题一看就是裸地LCT嘛,但是我wa了好几遍,这秘制标记...... 注意事项:I.*对+有贡献 II.先下传*再下传+(因为我们已经维护了+,不能再让*对+产生贡献)III.维护+用到size # ...

  2. Watto and Mechanism Codeforces Round #291 (Div. 2)

    C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  3. 桥接物理网卡,pipwork指定ip,外网连接,研究salt+docker

    1.桥接物理网卡: 首先下载工具: yum -y install --enablerepo=epel bridge-utils 停止服务: 983 systemctl stop docker 删除do ...

  4. c++(类) this指针

    this指针的相关概念: this只能在成员函数中使用.全局函数,静态函数都不能使用this.实际上,成员函数默认第一个参数为T* const register this. 为什么this指针不能再静 ...

  5. Java并发(6)- CountDownLatch、Semaphore与AQS

    引言 上一篇文章中详细分析了基于AQS的ReentrantLock原理,ReentrantLock通过AQS中的state变量0和1之间的转换代表了独占锁.那么可以思考一下,当state变量大于1时代 ...

  6. HDU1596 find the safest road---(最短路径dijkstra,#变形#)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 分析: 题目要找一条安全度最高的路,安全度计算方法    Safe(P) = s(e1)*s(e2)…*s ...

  7. [洛谷P2730] 魔板 Magic Squares

    洛谷题目链接:魔板 题目背景 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 题目描述 我们知道魔板的每一个方格都 ...

  8. 使用vs2010编辑Unity脚本,配置方法

    在Unity界面上.选择Edit->Preferences->External Tools,External Script Editor一项即为编译器. 以Unity3D 4.3.4 f1 ...

  9. 获取高德地图api

    先到高德开放平台首页按照关键字搜索地址,获取经纬度坐标: http://lbs.amap.com/console/show/picker 高德由坐标获取地址详细信息: http://restapi.a ...

  10. ubuntu设置默认python版本

    原文:https://www.cnblogs.com/johnny1024/p/8400511.html ··· ubuntu 16.04本身是自带python的,他本身是自带2.X和3.X,两个版本 ...