盒子游戏
有两个相同的盒子,其中一个装了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. Android 调整屏幕分辩率

    Android 可设置为随着窗口大小调整缩放比例及设定fixed的窗口大小. 对于surface的控制在SurfaceHolder类中进行 而Android 屏幕分辩率中已经有一个类DisplayMe ...

  2. cocos2d-x 实现clash of clans多点聚焦缩放场景

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=434 都是以前写的一些效果,整理 ...

  3. vim的ex模式用法

    本文出自   http://blog.csdn.net/shuangde800 本文是在学习<使用vi编辑器, Lamb & Robbins编著>时在evernote写的其中一章笔 ...

  4. 2014 I/O归来:Google连接一切

    6月,WWDC 2014与Google I/O  (大部分演讲视频都公开.Youtube须要FQ,很值得一看)相继召开.今年是我第三年參加Google I/O大会. 三年间.Google积累了非常多技 ...

  5. [转]java-Three Rules for Effective Exception Handling

    主要讲java中处理异常的三个原则: 原文链接:https://today.java.net/pub/a/today/2003/12/04/exceptions.html Exceptions in ...

  6. 1.1.4-学习Opencv与MFC混合编程之---画图工具 画椭圆

    源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961690 1.    增加‘椭圆’菜单项,设置属性,添加类向导: 2.    编辑消息处理函数, ...

  7. 浅谈数据库技术,磁盘冗余阵列,IP分配,ECC内存,ADO,DAO,JDBC

    整理-----数据库技术,磁盘冗余阵列,IP分配, ECC内存,ADO, DAO,JDBC 1.MySQL MySQL是最受欢迎的开源SQL数据库管理系统,它由 MySQL AB开发.发布和支持.My ...

  8. accept系统调用内核实现

    用户态对accept的标准使用方法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_siz ...

  9. JS - 焦点图

    下载地址:http://www.lanrentuku.com/js/jiaodiantu-1076.html 修改焦点图: CSS代码: /* 懒人图库 搜集整理 www.lanrentuku.com ...

  10. OO的ALV隐藏工具栏的form

    OO的ALV隐藏工具栏: ***展示数据 CALL METHOD gr_alvgrid->set_table_for_first_display EXPORTING is_variant = g ...