zoukankan      html  css  js  c++  java
  • UVA12293 Box Game

    UVA12293 Box Game

    题意

    两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球。每次操作都将刷量少的盒子的球倒掉,然后再从数量多的盒子中拿出若干个球放到空盒子里,最终状态为(1,1),达到这个状态的玩家获胜。

    题解

    显然原问题等价于有n个石子,每次至少拿一个,至多拿一半。

    对于这个问题:

    当n为奇数的时候 SG(n) = SG(n/2)

    当n为偶数的时候SG(n) = n/2

    #include<bits/stdc++.h>
    
    using namespace std;
    
    inline int read()
    {
        int f = 1 , x = 0;
        char ch;
        do
        {
            ch = getchar();
            if(ch == '-') f = -1; 
        }while(ch < '0' || ch > '9');
        do
        {
            x = (x<<3) + (x<<1) + ch - '0';
            ch = getchar();
        }while(ch >= '0' && ch <= '9');
        return f*x;
    } 
     
    int n;
     
    inline int SG(int x)
    {
         if(x&1) return SG(x/2);
         else return x/2;
    } 
     
    int main()
    {
         while(1)
         {
             n = read();
             if(!n) break;
             if(SG(n) == 0) cout << "Bob" << endl;
             else cout << "Alice" << endl;
        }
        return 0;
    }
  • 相关阅读:
    抉择
    PHP glob() 函数
    PHP之关闭网页错误提示
    PHP htmlentities() 函数
    PHP mysql_real_escape_string() 函数
    LFI & RFI & PHP封装协议之安全问题研究
    数据公钥加密和认证中的私钥公钥
    RSA算法
    APT攻防对抗
    安全参考
  • 原文地址:https://www.cnblogs.com/wlzs1432/p/13304710.html
Copyright © 2011-2022 走看看