ACM: NBUT 1107 盒子游戏 - 简单博弈
System Crawler (Aug 13, 2016 10:35:29 PM)
Description
面对两个各装一个球的盒子,Bob无法继续操作,因此Alice获胜。你的任务是找出谁会获胜。假定两人都很聪明,总是采取最优策略。
Input
Output
Sample Input
2
3
4
0
Sample Output
Alice
Bob
Alice
Hint
无
//思维题,简单博弈,直接插入走火入魔的题解。。。
//AC代码【递归写法】:
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
#include"map"
using namespace std;
typedef long long LL ;
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define FK(x) cout<<"["<<x<<"]\n"
#define bigfor(T) for(int qq=1;qq<= T ;qq++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 int fun(int n) {
int i=1;
while(i<n) {
i=i*2+1;
if(i==n)
return 1;
}
return 0;
}
int main() {
int n;
while(~scanf("%d",&n)) {
if(!n)break;
if(fun(n))
printf("Bob\n");
else
printf("Alice\n");
}
}
//AC代码【幂写法】:
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
#include"map"
using namespace std;
typedef long long LL ;
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define FK(x) cout<<"["<<x<<"]\n"
#define bigfor(T) for(int qq=1;qq<= T ;qq++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 int main() {
int n;
while(~scanf("%d",&n)) {
if(!n)break;
if(n%2==0) {
puts("Alice");
continue;
}
n+=1;
while(n) {
if(n==1) {
puts("Bob");
break;
}
if(n%2) {
puts("Alice");
break;
}
n/=2;
}
}
return 0;
}
ACM: NBUT 1107 盒子游戏 - 简单博弈的更多相关文章
- NBUT 1107——盒子游戏——————【博弈类】
盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 110 ...
- 取球游戏_nyoj_518(博弈-蓝桥杯原题).java
取球游戏 时间限制: 1000 ms | 内存限制: 65535 KB 难度: 2 描述 今盒子里有n个小球,A.B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下 ...
- 盒子游戏(The Seventh Hunan Collegiate Programming Contest)
盒子游戏 有两个相同的盒子,其中一个装了n个球,另一个装了一个球.Alice和Bob发明了一个游戏,规则如下:Alice和Bob轮流操作,Alice先操作.每次操作时,游戏者先看看哪个盒子里的球的数目 ...
- HDU 1564 简单博弈 水
n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...
- 1254: 盒子游戏(Java)
WUSTOJ 1254: 盒子游戏 参考博客 叶剑飞Victor的博客 盒子游戏--爱程序网 原理是从上面博客看的,我另外补充了几幅图,方便理解 Description 有两个相同的盒子,其中一个装了 ...
- acm之简单博弈 Nim Bash Wythoff
前些日子我打算开了博弈基础,事后想进行总结下 一句话就是分析必胜或必败,异或为0. 以下内容来自转载: Nim游戏的概述: 还记得这个游戏吗?给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠 ...
- 51nod 1066 - Bash游戏,简单博弈
有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N和K,问最后谁能赢得比赛. 例如N = 3 ...
- HDU 1079 Calendar Game(简单博弈)
Calendar Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1846 Brave Game 简单博弈
Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中 ...
随机推荐
- Eclipse DDT
http://www.eclipse.org/downloads/ https://github.com/DDT-IDE/DDT/blob/latest/documentation/UserGuide ...
- SQLite的时候判断语句是否纯在:出现RuntimeException
写SQLite的时候判断语句是否纯在: public boolean exist(long id) { String filter = FRIEND_KEY_ID + "=" + ...
- Reprint: ADB is Not Recognized as an internal or external command Fix
ADB: Android Debug Bridge http://zacktutorials.blogspot.hk/2013/04/adb-is-not-recognized-as-internal ...
- Linux下查看操作系统信息、内存情况及cpu信息:cpu个数、核心数、线程数
1.查看物理CPU的个数 [root@MysqlCluster01 ~]# cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc ...
- idea之internal java compiler error
启动错误:Error:java: Compilation failed: internal java compiler error 解决:将圈选地方改为对应的jdk版本即可
- 欢迎加入threejs
Threejs is the coolest graphics rendering engine I have ever seen, so what is threejs, Now, we have ...
- 【GWAS文献】基于GWAS与群体进化分析挖掘大豆相关基因
Resequencing 302 wild and cultivated accessions identifies genes related to domestication and improv ...
- html中表格元素的相关总结
表格元素相关总结: 1.在CSS中,内部表元素(如td.tr.col等)生成矩形框,这些矩形框包含内容.内边距和边框,但没有外边距,因此如果定义外边距,浏览器将忽略该定义:对于table元素,外边距有 ...
- Spark集群部署
Spark是通用的基于内存计算的大数据框架,可以和hadoop生态系统很好的兼容,以下来部署Spark集群 集群环境:3节点 Master:bigdata1 Slaves:bigdata2,bigda ...
- Python多进程(2)——mmap模块与mmap对象
本文介绍Python mmap模块与mmap对象的用法. mmap 模块提供“内存映射的文件对象”,mmap 对象可以用在使用 plain string 的地方,mmap 对象和 plain stri ...
