• [hdu1847]博弈,推理


    题意:一堆石子,有n个,两个人轮流取,每次都只能取2的幂次方个数,不能取的人输

    思路:首先0是必败态,2的所有幂次都是必胜态。由于选的数模3只能是1或2,恰好又都是2的幂次,0,、3都为必败态,猜想3的所有倍数也为必败态,证明如下:设状态为x=3k,先手任选一个t,那么(x-t)%3不是1就是2,后手就取(x-t)%3,使得先手面临的状态始终是3的倍数,并且只要先手可以取,那么后手也就可以取,所以3的倍数都是必败态。对于x=3k+p,p=1或2的状态,先手都可以将其变成必败态,即先手取p=x%3即可,因此为必胜态。


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    /* ******************************************************************************** */
    #include <iostream>                                                                 //
    #include <cstdio>                                                                   //
    #include <cmath>                                                                    //
    #include <cstdlib>                                                                  //
    #include <cstring>                                                                  //
    #include <vector>                                                                   //
    #include <ctime>                                                                    //
    #include <deque>                                                                    //
    #include <queue>                                                                    //
    #include <algorithm>                                                                //
    #include <map>                                                                      //
    #include <cmath>                                                                    //
    using namespace std;                                                                //
                                                                                        //
    #define pb push_back                                                                //
    #define mp make_pair                                                                //
    #define X first                                                                     //
    #define Y second                                                                    //
    #define all(a) (a).begin(), (a).end()                                               //
    #define fillchar(a, x) memset(a, x, sizeof(a))                                      //
                                                                                        //
    typedef pair<intint> pii;                                                         //
    typedef long long ll;                                                               //
    typedef unsigned long long ull;                                                     //
                                                                                        //
    #ifndef ONLINE_JUDGE                                                                //
    void RI(vector<int>&a,int n){a.resize(n);for(int i=0;i<n;i++)scanf("%d",&a[i]);}    //
    void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>                    //
    void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?1:-1;          //
    while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>      //
    void print(const T t){cout<<t<<endl;}template<typename F,typename...R>              //
    void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>   //
    void print(T*p, T*q){int d=p<q?1:-1;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}   //
    #endif // ONLINE_JUDGE                                                              //
    template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}        //
    template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}        //
    template<typename T>                                                                //
    void V2A(T a[],const vector<T>&b){for(int i=0;i<b.size();i++)a[i]=b[i];}            //
    template<typename T>                                                                //
    void A2V(vector<T>&a,const T b[]){for(int i=0;i<a.size();i++)a[i]=b[i];}            //
                                                                                        //
    const double PI = acos(-1.0);                                                       //
    const int INF = 1e9 + 7;                                                            //
                                                                                        //
    /* -------------------------------------------------------------------------------- */
     
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt""r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE
        int n;
        while (cin >> n) {
            puts(n % 3? "Kiki" "Cici");
        }
        return 0;
    }
    /* ******************************************************************************** */
  • 相关阅读:
    apple苹果产品国行和港行的区别
    iOS ifdef ifndef endif
    objectiveC【语法】修饰符 static extern const
    iOS关于Xcode上的Other linker flags
    win7 64位旗舰版下载
    关于ios 和 android 录音(语音)对聊文件格式问题
    关于 NSData 的数据类型(2进制,16进制之间)及深入剖析
    iOS调用系统相册、相机 显示中文标题
    xcode各个版本下载 xcode7 xcode6 xcode5
    IOS开发之----全局变量extern的使用
  • 原文地址:https://www.cnblogs.com/jklongint/p/4700715.html
Copyright © 2020-2023  润新知