盒子游戏
有两个相同的盒子,其中一个装了n个球,另一个装了一个球。Alice和Bob发明了一个游戏,规则如下:Alice和Bob轮流操作,Alice先操作。每次操作时,游戏者先看看哪个盒子里的球的数目比较少,然后清空这个盒子(盒子里的球直接扔掉),然后把另一个盒子里的球拿一些到这个盒子中,使得两个盒子都至少有一个球。如果一个游戏者无法进行操作,他(她)就输了。下图是一个典型的游戏:
面对两个各装一个球的盒子,Bob无法继续操作,因此Alice获胜。你的任务是找出谁会获胜。假定两人都很聪明,总是采取最优策略。
输入
输入最多包含300组测试数据。每组数据仅一行,包含一个整数n(2<=n<=109)。输入结束标志为n=0。
输出
对于每组数据,输出胜者的名字。
样例输入
2
3
4

0

样例输出

Alice
Bob

Alice

分析:通过找规律,我可以的到,只要给出的数据是2^n-1那么就是Bob赢,反之就是Alice赢

代码:

#include<iostream>
#include<cmath>
using namespace std;
int pow(int p){
int sum=1;
while(p){
sum=sum*2;
p--;
}
return sum;
}
int main(){
int n;
int i,j;
while(cin>>n&&n>0){
int temp=0;
for(int i=1;pow(i)-1<=n;i++){
if(n==pow(i)-1){temp++;}}
if(temp==0){cout<<"Alice"<<endl;}
else{cout<<"Bob"<<endl;}
}
return 0;
}

盒子游戏(The Seventh Hunan Collegiate Programming Contest)的更多相关文章

  1. 一二三(The Seventh Hunan Collegiate Programming Contest)

    一二三 你弟弟刚刚学会写英语的一(one).二(two)和三(three).他在纸上写了好些一二三,可惜有些字母写错了.已知每个单词最多有一个字母写错了(单词长度肯定不会错),你能认出他写的啥吗? 输 ...

  2. The Ninth Hunan Collegiate Programming Contest (2013) Problem A

    Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem H

    Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem I

    Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...

  6. The Ninth Hunan Collegiate Programming Contest (2013) Problem J

    Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  8. The Ninth Hunan Collegiate Programming Contest (2013) Problem L

    Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...

  9. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

随机推荐

  1. 跟着鬼哥学so改动,一,准备篇

    图/文 听鬼哥说故事 闲话少说,so的改动,重要性大家都知道,这里从头编写so文件,分析so文件,改动so文件,打算做一个系列的教程,当然,主要是看时间同意. android的sdk配置以及ndk环境 ...

  2. Swift - 设置应用程序图标的提醒个数(右上角小红圈)

    使用UILocalNotification除了可以实现本地消息的推送功能(可以设置推送内容,推送时间,提示音),还可以设置应用程序右上角的提醒个数. 下面演示如何设置,效果图如下: --- AppDe ...

  3. HTML+CSS - 搜索 And 高级搜索

  4. node-inspector使用

    nodejs.gulp调试工具node-inspector使用 俗话说欲善其功,必先利其器. 作为目前新型的Web Server开发栈倍受开发者关注的Nodejs来说,调试技术是学习开发的基石,所以对 ...

  5. mongdb修改密码

    正确做法,利用db.changeUserPassword > db.changeUserPassword('tank2','test');

  6. css3 animation 参数详解

    animation: name 2s ease 0s 1 both有人知道这后面的参数都代表什么意思吗 name 就是你创建动画的名称 2S表示的时长 ease表示运动效果 0S表示延迟时间 1表示的 ...

  7. FZU 1894 (双端队列)

    Problem 1894 志愿者选拔 Accept: 1166    Submit: 3683 Time Limit: 1500 mSec    Memory Limit : 32768 KB  Pr ...

  8. javascript 高级程序设计 学习笔记

    <!--<script> // 异步请求封装 IE6即以上浏览器 // ajax(url,fnSucc,selectID,fnFaild) //url 请求地址 //fnSucc 异 ...

  9. mysql基础: mysql列类型--字符串

    mysql列类型:整型   http://blog.csdn.net/jk110333/article/details/9342283 mysql列类型--时间和日期  http://blog.csd ...

  10. HDU 1269 迷宫城堡(强连通)

    HDU 1269 迷宫城堡 pid=1269" target="_blank" style="">题目链接 题意:中文题 思路:强连通模板题 代 ...