Box Game

There are two identical boxes. One of them contains n balls, while the other box contains one ball. Alice and Bob invented a game with the boxes and balls, which is played as follows:

Alice and Bob moves alternatively, Alice moves first. For each move, the player finds out the box having fewer number of balls inside, and empties that box (the balls inside will be removed forever), and redistribute the balls in the other box. After the redistribution, each box should contain at least one ball. If a player cannot perform a valid move, he loses. A typical game is shown below:

When both boxes contain only one ball, Bob cannot do anything more, so Alice wins.

Question: if Alice and Bob are both clever enough, who will win? Suppose both of them are very smart and always follows a perfect strategy.

Input

There will be at most 300 test cases. Each test case contains an integer n ( 2n109) in a single line. The input terminates by n = 0.

Output

For each test case, print a single line, the name of the winner.

Sample Input

2
3
4
0

Sample Output

Alice
Bob
Alice

分析:博弈论问题
#include<stdio.h>
int num;
int main()
{
    int flag,p;
    while(scanf("%d",&num)!=EOF){
        if(num==0) break;
        flag=1;
        if(num==2){
            printf("Alice\n");
            continue;
        }
        if(num==3){
            printf("Bob\n");
            continue;
        }
         p=num;
        for(int i=0;;i++){
            if(p%2==0) break;
            else{
                p=(p-1)/2;
                if(p>3) continue;
                if(p<=2) break;
                if(p==3){
                    printf("Bob\n");
                    flag=0;
                    break;
                }
            }

        }
        if(flag)
        printf("Alice\n");
        if(!flag) continue;
    }
    return 0;
}

参考代码:

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<ctime>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Master Love
#define YYF Handsome
#define Rp Maxunsignedlonglongint
#define Orz zhanhb8 qs1994
#define Designer Zero
#define zhx zh[x]
#define lth th<<1
#define rth th<<1|1
#define middle (nl+nr)>>1
#define MAX(a,b)  (a>b)?a:b
#define MIN(a,b)  (a<b)?a:b
#define getlen(s)  strlen(s+1)
#define outputans cout<<ans<<endl
#define inputint(k) scanf("%d",&k)
#define inputchar(c) scanf("%c",&c)
#define input64(k) scanf("%I64d",&k)
#define inputdouble(k) scanf("%lf",&k)
#define inputstring(s) scanf("%s",s+1)
#define forout(i,l,r) for(i=l;i<=r;i++)
#define forin(i,l,r) for(int i=l;i<=r;i++)
#define clearit(a,k) memset(a,k,sizeof(a))
#define formatrix for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)
#pragma warning(disable:4996)
using namespace std;
int T;
char s[521];
int sg[101][101] = { 0 };
int val[31] = { 0 };
int main(){
    val[0] = 1;
    for (int i = 1; i <= 30; i++)val[i] = val[i - 1] * 2;
    int n;
    while (1){
        inputint(n);
        if (!n)break;
        bool pos = 0;
        for (int i = 2; i <= 30; i++)if(val[i]-1==n)pos=1;
        if (pos)printf("Bob\n");
        else printf("Alice\n");
    }
    return 0;
}

Box Game

时间: 2024-10-30 17:11:56

Box Game的相关文章

Windows10 使用Virtual Box一启动虚拟机就蓝屏(错误代码SYSTEM_SERVICE_EXCEPTION)解决方案

原文:Windows10 使用Virtual Box一启动虚拟机就蓝屏(错误代码SYSTEM_SERVICE_EXCEPTION)解决方案 一打开虚拟机电脑就立马蓝屏重启,新建虚拟机也没用,然后就开始百度,百度上全说什么驱动不对,然后我就卸载升级各种驱动,然后各种重装VirtualBox,还是不行,搞了一两个小时,都快放弃了.决定上个google,终于看到一篇文章说是因为Hyper-V与Virtual Box冲突了,只需要在控制面板关闭就行.然后抱着试一试的心态. 首先我们先打开控制面板.按Wi

CloudFoundry in 1 Box简介:PCF-Dev篇

在<CloudFoundry in 1 Box简介:Bosh-lite篇>我们介绍了Bosh-lite的架构和部署.在本篇中,我们将详细描述另一个CloudFoundry in 1 Box解决方案PCF-Dev. 1PCF-dev简介 PCF是Pivotal发行的Cloud Foundry商业版,PCF-Dev原名MicroPCF,是Pivotal为PCF的应用开发人员准备的一款App单虚拟机版的CloudFoundry.但是,麻雀虽小,五脏俱全.PCF-Dev虽然可以在仅仅一台虚拟式上即可运

CodeForces 388A Fox and Box Accumulation 贪心

Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cann

poj1442(Black Box)

题目地址:Black Box 题目大意: 有一个黑盒子可以进行两种操作,一种是ADD往盒子里存数,一种是GET查找盒子里的第几个数,默认盒子里始终是从小到大排列,然后A(1).A(2)....A(M)为要存进盒子的数,u(1).u(2).....u(N)的数并不是取出第几个数,而这里u(N)存的数是插入几个A(M)到盒子里去,这里有一个P(1 <= p <= N) 和u是同序列的.输出 p-minimum number from our A(1), A(2), ..., A(u(p)) seq

Flexible Box布局基础知识详解

1.基本概念,借用阮一峰老师的一张图: 容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis).主轴的开始位置(与边框的交叉点)叫做main start,结束位置叫做main end:交叉轴的开始位置叫做cross start,结束位置叫做cross end. 项目默认沿主轴排列.单个项目占据的主轴空间叫做main size,占据的交叉轴空间叫做cross size. 2.容器的基本属性 flex-direction flex-wrap flex-flow j

Vagrant box ubuntu/xenial64 没有密码的解决方法

参考了Vagrant box ubuntu/xenial64 の ubuntuユーザ の passwordについて 1. 可以通过 Git Bash 使用  vagrant ssh 登录到Ubuntu/xenial64的终端中 2. 在终端中输入: vim useradd.sh 文件内容 #!/bin/bash set -Ceu USER="vagrant" # password "vagrant" を SHA-512 でハッシュ化 PASSWORD=$(perl

adminLTE 教程 -6 多box

多box相比box来说使用的场景并不多 <div class="box box-solid"> <div class="box-header with-border"> <h3 class="box-title">Collapsible Accordion</h3> </div> <!-- /.box-header --> <div class="box-bo

windows下安装virtual box(ubuntu)

由于自己安装时出现了很多的问题,特意Mark一下. 第一步:在BIOS里是开启虚拟化(参考网上教程的)https://zhidao.baidu.com/question/1894752363981711700.html 1.重启电脑后按F2或F10进入BIOS界面: 2.进入界面后,依次选择Configuratio > Intel Virtual Technology > Enabled: 3.保存BIOS设置并重启电脑. 第二步:安装virtual box,我安装的版本是5.1.0. 下载地

在Virtual Box上安装linux系统,启动SSH服务

? 一.????在Virtual Box上创建虚拟机????1 二.????安装linux系统????6 三.????重新设置 root 的密码:????8 四.????启动ssh服务????8 五.????建立共享文件夹????9 ? ? 摘自以下网页内容: 如何在Virtual Box上安装linux系统 : http://jingyan.baidu.com/album/2009576197fd24cb0721b409.html?picindex=1 Linux终端得到root权限 :htt

Kidney自得其乐版CSS教程 Chapter2 Box Model

Chapter 2 Box Model Version Update Note 1.0 2016-5-31 首次添加.欢迎在评论中指出错误,一经核实,立即修订,且注明贡献者. 1.元素的分类        1.1 替换元素 替换元素就是替身元素,它替别人占个位,它不是普通的标签,它代表某种元件. 例如:<img> <source><input><embed>……        1.2 非替换元素 大部分元素都是非替换元素. 从形式上看非替换元素是一对标签,替