盒子游戏(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 ...
随机推荐
- 刘德华夏日Fiesta演唱会上那个表演探戈舞的演员是谁啊?_百度知道
刘德华夏日Fiesta演唱会上那个表演探戈舞的演员是谁啊?_百度知道 刘德华夏日Fiesta演唱会上那个表演探戈舞的演员是谁啊? 2008-05-28 00:04 topofhill | ...
- [ACM] n划分数m部分,它要求每一个部分,并采取了最大的产品(间隔DP)
A - 爱管闲事 春希很爱管闲事,他每天都会抽出时间帮助一些同学,因为春希很死板,出于公平性,春希不会先帮助后来找他的同学. 如今有n个同学须要他的帮助,尽管他非常想一天之类帮助全部人,但毕竟精力有限 ...
- Java ArrayList add(int index, E element) example
Simple add() method is used for adding an element at the end of the list however there is another va ...
- MSSQL - SqlDataAdapter连接数据库提高性能用法
SqlDataAdapter 与 SqlConnection 和 SqlCommand 一起使用,以便在连接到 SQL Server 数据库时提高性能. SqlDataAdapter 的这一实现自动打 ...
- python获取实时股票信息
Python3获取股票行情数据(中国个股/中国指数/全球指数) #!/usr/local/bin/python3 #coding=utf-8 #source http://www.cnblogs.co ...
- oracle flashback 2
Flashback database After oracle 10g, oracle can rollback to an prior time by flashback databas ...
- gbs remotebuild使用说明
本文件从:https://source.tizen.org/documentation/articles/gbs-remotebuild翻译而来. 1 远程构建 使用remotebuild子指令将本地 ...
- JDK1.5后的新特性之一:可变参数
Java中的可变参数 Java1.5后出现了一个新特性,即可变参数,格式为:类型 …参数 例如: 总的来说,可变参数可以当成是数组来用: public void testSum() { System. ...
- Spring Boot,Spring Data JPA多数据源支持
1 配置文件 wisely.primary.datasource.driverClassName=oracle.jdbc.OracleDriver wisely.primary.datasource. ...
- 【Cloud Foundry】Could Foundry学习(二)——核心组件分析
在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com QQ:1494713801 Cloud Foundry核心组件架构图例如以下: 主要组件: Clou ...