盒子游戏(The Seventh Hunan Collegiate Programming Contest)
盒子游戏
有两个相同的盒子,其中一个装了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)的更多相关文章
- 一二三(The Seventh Hunan Collegiate Programming Contest)
一二三 你弟弟刚刚学会写英语的一(one).二(two)和三(three).他在纸上写了好些一二三,可惜有些字母写错了.已知每个单词最多有一个字母写错了(单词长度肯定不会错),你能认出他写的啥吗? 输 ...
- 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 ...
- 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 ...
- 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. ...
- 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: ...
- 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, ...
- 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 ...
- 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 ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...
随机推荐
- [REST Jersey] @QueryParam Demo
This demo sourced from the jersey tutor. https://jersey.java.net/documentation/latest/jaxrs-resource ...
- C#、WinForm、ASP.NET - Md5散列加密
MD5值概念解释: 转载自:http://free0007.iteye.com/blog/2047163 所 谓MD5,即"Message-Digest Algorithm 5(信息-摘要 ...
- QT+vs2010下改变可执行程序的图标
原地址:http://blog.163.com/tijijun@126/blog/static/6820974520134209457308/ 在解决方案下面的工程里,点击右键 ->选择[添加( ...
- C keyword register 并讨论共同使用嵌入式汇编
C keyword register 并讨论共同使用嵌入式汇编 register 是C99 的keyword之中的一个. register 是储存类型之中的一个.这里仅讨论register 储存类型. ...
- listview——显示窗体
listview——是用来显示的控件 一,属性 view:(显示的视图)LargeIcon——大图标:SmallIcon——小图标:Details——详细:List——列表:TItle——平铺 Sma ...
- android花屏效果的实现(ViewPager的基本使用)
1.程序运行效果图 二.代码实现 1.main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/re ...
- Custom draw 和 Owner draw 的区别
"Custom Draw" is a feature shared by all of Microsoft's common controls, which allows you ...
- PostgreSQL的备份与还原
导出: cmd,然后一直cd,到PostgreSQL的bin下面,用其pg_dump程序: pg_dump -h localhost -U ivms864013 ivms864013 > G:\ ...
- javascript (八) 语法格式
JavaScript 对大小写敏感. JavaScript 对大小写是敏感的. 当编写 JavaScript 语句时,请留意是否关闭大小写切换键. 函数 getElementById 与 getEle ...
- Delphi/C#之父首次访华:55岁了 每天都写代码
Delphi.C#之父Anders Hejlsberg 近日首次访华,并在10月24日和27日参加了两场见面会,分享了他目前领导开发的TypeScript项目,并与国内前端开发者近距离交流.本文就为读 ...