• hdu 2516博弈找规律


    http://acm.hdu.edu.cn/showproblem.php?pid=2516

    这道题就是简单的博弈,但是分析时候要一点时间。

    分析:

    n =2时输出second

    n =3时也是输出second

    n =4时,第一个人想获胜就必须先拿1个,这时剩余的石子数为3,此时无论第二个人如何取,第一个人都能赢,输出first

    n =5时,first不可能获胜,因为他取2时,second直接取掉剩下的3个就会获胜,当他取1时,这样就变成了n4的情形,所以输出的是second

    n =6时,first只要去掉1个,就可以让局势变成n5的情形,所以输出的是first

    n =7时,first取掉2个,局势变成n5的情形,故first赢,所以输出的是first

    n =8时,当first1的时候,局势变为7的情形,第二个人可赢,first2的时候,局势变成n6得到情形,也是第二个人赢,取3的时候,second直接取掉剩下的5个,所以n =8时,输出的是second

    …………

    从上面的分析可以看出,n2358时,这些都是输出second,即必败点,仔细的人会发现这些满足斐波那契数的规律,可以推断13也是一个必败点。

    n =12时,只要谁能使石子剩下8且此次取子没超过3就能获胜。因此可以把12看成8+4,把8看成一个站,等价与对4进行”气喘操作“。

    又如1313=8+55本来就是必败态,得出13也是必败态。

    
    
    

    也就是说,只要是斐波那契数,都是必败点。

    所以我们可以利用斐波那契数的公式:fib[i]= fib[i-1]+ fib[i-2],只要n是斐波那契数就输出second

    View Code
    // I'm lanjiangzhou
    //C
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    #include <time.h>
    //C++
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <cctype>
    #include <stack>
    #include <string>
    #include <list>
    #include <queue>
    #include <map>
    #include <vector>
    #include <deque>
    #include <set>
    using namespace std;
    
    //*************************OUTPUT*************************
    #ifdef WIN32
    #define INT64 "%I64d"
    #define UINT64 "%I64u"
    #else
    #define INT64 "%lld"
    #define UINT64 "%llu"
    #endif
    
    //**************************CONSTANT***********************
    #define INF 0x3f3f3f3f
    
    // aply for the memory of the stack
    //#pragma comment (linker, "/STACK:1024000000,1024000000")
    //end
    
    const int maxn = 110;
    int f[maxn];
    int main(){
        int n;
        //memset(f,0,sizeof(f));
        //F[0]=0;
        //F[1]=1; F[2]=2; F[3]=3;
        f[0]=2; f[1]=3;
        for(int i=2;i<44;i++){
            f[i]=f[i-1]+f[i-2];
            //printf("%d\n",f[i]);
        }
        while(scanf("%d",&n)!=EOF){
            int flag=0;
            if(n==0) break;
            for(int i=0;i<44;i++){
                if(f[i]==n){
                    flag=1;
                    break;
                }
            }
            if(flag) printf("Second win\n");
            else printf("First win\n");
        }
        return 0;
    }
  • 相关阅读:
    Redis 详解 (一) StackExchange.Redis Client
    redis在.net架构中的应用(1)--利用servicestack连接redis
    .NET中使用Redis:http://www.cnblogs.com/yangecnu/p/Introduct-Redis-in-DotNET.html
    SQL Server日期函数总结
    SQL Server 日期和时间函数
    16Aspx源码论坛
    方差和偏差的区别
    写在中秋节的前?秒
    装系统那些事儿-1-电脑的启动流程
    查找重复的数
  • 原文地址:https://www.cnblogs.com/lanjiangzhou/p/3019813.html
Copyright © 2020-2023  润新知