盒子游戏(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 ...
随机推荐
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- Eclipse用法和技巧四:生成说明文档1
写代码经常要添加注释的,java代码的注释也可以分为两种.单行注释以“//”作为开头就可以.段落注释在第一行开头添加“/*”,在最后一行结尾添加“*/"即可.这里介绍一种添加注释的方法,其注 ...
- Win2003 Server磁盘配额揭密之启用篇
Win2003 Server磁盘配额揭密之启用篇 [ 作者:茶乡浪子 转贴自:it168.com 点击数:4973 更新时间:2005-1-17 ] 本文要向大家介绍如何利用W ...
- 【图像识别】 图像处理和图像分析(leptonica)leptonica-1.68安装配置 (vs2008)
Leptonica Leptonica is a pedagogically-oriented open source site containing software that is broadly ...
- 延迟函数 比sleep效果好
sleep是会阻塞线程的 网上有些延迟函数测试下来还是会阻塞,而接下来推荐的代码则不会 1 2 3 4 5 6 7 8 9 procedure delay(dwMilliseconds:integ ...
- GetCursorPos/WindowFromPoint/SendMessage
GetCursorPos/WindowFromPoint/SendMessage (用API函数向Edit框发送字符) GetCursorPos(mPoint); DTWND:=WindowFromP ...
- 也谈C#之Json,从Json字符串到类代码
原文:也谈C#之Json,从Json字符串到类代码 阅读目录 json转类对象 逆思考 从json字符串自动生成C#类 json转类对象 自从.net 4.0开始,微软提供了一整套的针对json进 ...
- Windows server 2008 R2实现多用户远程连接
原文 Windows server 2008 R2实现多用户远程连接 经常使用远程桌面的朋友可能会注意到,Windows server 2008 R2中,远程桌面最多只允许两个人远程连接,第三个人就无 ...
- 不用splitter控件 简单实现对mfc对话框的分割的方法
不用splitter控件 简单实现对mfc对话框的分割的方法 直接贴上源代码主要部分吧 这个是基于对话框的工程 进行对话框的分割实现 只是相应了三个消息函数,看一下就会明白的 我空间资源里边有现成的 ...
- 与众不同 windows phone (2) - Control(控件)
原文:与众不同 windows phone (2) - Control(控件) [索引页][源码下载] 与众不同 windows phone (2) - Control(控件) 作者:webabcd介 ...