zoukankan      html  css  js  c++  java
  • HDU 1848 Fibonacci again and again SG函数做博弈

    传送门

    题意:

      有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数。

    思路:

      利用SG函数求解即可。

    /*
    * @Author: chenkexing
    * @Date:   2019-01-13 16:17:46
    * @Last Modified by:   chenkexing
    * @Last Modified time: 2019-01-15 11:10:33
    */
    
    #include <algorithm>
    #include  <iterator>
    #include  <iostream>
    #include   <cstring>
    #include   <cstdlib>
    #include   <iomanip>
    #include    <bitset>
    #include    <cctype>
    #include    <cstdio>
    #include    <string>
    #include    <vector>
    #include     <stack>
    #include     <cmath>
    #include     <queue>
    #include      <list>
    #include       <map>
    #include       <set>
    #include   <cassert>
    
    using namespace std;
    #define lson (l , mid , rt << 1)
    #define rson (mid + 1 , r , rt << 1 | 1)
    #define debug(x) cerr << #x << " = " << x << "
    ";
    #define pb push_back
    #define pq priority_queue
     
     
    
    typedef long long ll;
    typedef unsigned long long ull;
    //typedef __int128 bll;
    typedef pair<ll ,ll > pll;
    typedef pair<int ,int > pii;
    typedef pair<int,pii> p3;
     
    //priority_queue<int> q;//这是一个大根堆q
    //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
    #define fi first
    #define se second
    //#define endl '
    '
     
    #define OKC ios::sync_with_stdio(false);cin.tie(0)
    #define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
    #define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
    #define max3(a,b,c) max(max(a,b), c);
    #define min3(a,b,c) min(min(a,b), c);
    //priority_queue<int ,vector<int>, greater<int> >que;
     
    const ll mos = 0x7FFFFFFF;  //2147483647
    const ll nmos = 0x80000000;  //-2147483648
    const int inf = 0x3f3f3f3f;
    const ll inff = 0x3f3f3f3f3f3f3f3f; //18
    const int mod = 1e9+7;
    const double esp = 1e-8;
    const double PI=acos(-1.0);
    const double PHI=0.61803399;    //黄金分割点
    const double tPHI=0.38196601;
     
     
    template<typename T>
    inline T read(T&x){
        x=0;int f=0;char ch=getchar();
        while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
        while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
        return x=f?-x:x;
    } 
    /*-----------------------showtime----------------------*/
                const int maxn = 1009;
                ll f[50];
                int sg[maxn],s[maxn];
    
                void getSG(int n){
    
                      for(int i=1; i<=n; i++){
                            memset(s,0,sizeof(s));
                            for(int j=1; f[j] <= i && j<=20; j++){
                                  s[sg[i-f[j]]] = 1;
                            }
                            for(int j=0; ; j++) if(!s[j]){
                                  sg[i] = j;
                                  break;
                            }
                      }
                }
    int main(){ 
                      f[1] = 1;f[2] = 1;
                      for(int i=3; i<=20; i++) f[i] = f[i-1] + f[i-2];
                      getSG(1000);
                      int a,b,c;
                      while(~scanf("%d%d%d", &a, &b, &c) && a+b+c){
                            if(sg[a] ^ sg[b] ^ sg[c]) puts("Fibo");
                            else puts("Nacci");
                      }
                      return 0;
    }
    View Code
  • 相关阅读:
    心跳机制
    C++虚继承和虚基类
    STL,ATL与WTL
    C# Task的暂停与终止
    C#继承
    C#线程同步问题
    CourtAi发布配置文件修改说明
    阿里云虚拟主机https化步骤第一篇,申请证书(笔记)
    linux 服务器重启指令
    .net core 发布到iis问题 HTTP Error 500.30
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/10270861.html
Copyright © 2011-2022 走看看