zoukankan      html  css  js  c++  java
  • POJ 3537 Crosses and Crosses (NEERC)

                      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*20];
    inline void init(){
        sg[0]=sg[1]=sg[2]=0;
        sg[3]=sg[4]=sg[5]=1;
        
        int now,x,y;
        for(int i=6;i<=2002;i++){
            v[sg[i-3]]=i;
            x=1,y=i-4;
            while(x<=y){
                v[sg[x]^sg[y]]=i;
                x++,y--;
            }
            
            now=0;
            while(v[now]==i) now++;
            sg[i]=now;
        }
    }
    
    int main(){
        init();
    //    for(int i=1;i<=20;i++) printf("%d %d
    ",i,sg[i]);
        while(scanf("%d",&n)==1){
            if(sg[n+2]) puts("1");
            else puts("2");
        }
        return 0;
    }
  • 相关阅读:
    Asp中JSON的使用
    POJ 3243 Clever Y Extended-Baby-Step-Giant-Step
    [Java开发之路](16)学习log4j日志
    【剑指Offer学习】【面试题49:把字符串转换成整数】
    负载均衡器&amp;http正向代理
    Android应用开发经常使用知识
    java8_api_nio
    李洪强经典面试题25(选择题)
    李洪强经典面试题24
    李洪强经典面试题23
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8340420.html
Copyright © 2011-2022 走看看