1349: Taking Pebbles (博弈 打表找规律)
1349: Taking Pebbles
Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 233 Solved: 141
Description
There is a pile of N pebbles initially. Alice and Bob are playing a taking pebbles game as follows:
Alice and Bob moves by turns, Alice moves first. For each move, the player can takes away at least one and at most half of the pebbles remained (“at most half” means you can take way at most k (k >= 1) pebbles if there are 2*k or 2*k+1 pebbles remained). If there is only one pebble remained, the player can also take away this pebble. The player who takes away the last pebble wins.
If Alice and Bob are both clever enough, and they both want to be the winner, who will win?
Input
The first line has one integer T (1 <= T <= 200), means there are T test cases.
For each test case, there is only one line with an integer N (2 <= N <= 109), means the number of pebbles initially.
Output
For each test case, print “Alice” (without quotation marks) in one line if Alice will win. Otherwise print “Bob” (without quotation marks) instead.
Sample Input
5
2
3
4
5
6
Sample Output
Bob
Alice
Alice
Bob
Alice
Hint
Source
中南大学第一届长沙地区程序设计邀请赛
一般都是打个表,找找看有没有规律
因为答案就两种情况
肯定是跟n有关
那可能是有规律的......
试着打个表
果然!!!!!
n为以下数字的时候
2
5
11
23
47
95
191
383
767
Bob赢
找到这个规律之后
还pe,re了好几发
因为还想着把表存下来....
真是傻得一批
直接判断一下不是不是这些数字就可以了啊
.....
void dabiao()
{
f[]=;
f[]=;
for(int i=; i<=; i++)
{
int flag=;
int x=i/;
if(i%)
x=i/+;
for(int j=i-; j>=x; j--)
{
if(f[j]==)
{
flag=;
break;
}
}
if(flag==)
{
f[i]=;
}
} for(int i=; i<=; i++)
{
if(f[i]==)
{
printf("%d\n",i);
}
}
}
code:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<memory.h>
#include<memory>
using namespace std;
#define max_v 1005
#define max_n 1000
typedef long long LL;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
if(n%==&&n!=)
printf("Alice\n");
else if(n==)
printf("Bob\n");
else
{
int k=;
while(k<n)
{
k=k*+;
}
if(k==n)
printf("Bob\n");
else
printf("Alice\n");
}
}
return ;
}
/*
碰到这种题就有点郁闷,因为写的很少
一般都是打个表,找找看有没有规律
因为答案就两种情况
肯定是跟n有关
那可能是有规律的......
试着打个表
果然!!!!!
n为以下数字的时候
2
5
11
23
47
95
191
383
767
Bob赢
找到这个规律之后
还pe,re了好几发
因为还想着把表存下来....
真是傻得一批
直接判断一下不是不是这些数字就可以了啊
..... */
/*
2
5
11
23
47
95
191
383
767
*/
1349: Taking Pebbles (博弈 打表找规律)的更多相关文章
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- vijos 1004 伊甸园日历游戏 博弈+打表找规律
描述 Adam和Eve玩一个游戏,他们先从1900.1.1到2001.11.4这个日期之间随意抽取一个日期出来.然后他们轮流对这个日期进行操作: 1 : 把日期的天数加1,例如1900.1.1变到19 ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU-4664 Triangulation 博弈,SG函数找规律
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4664 题意:一个平面上有n个点(一个凸多边形的顶点),每次可以连接一个平面上的两个点(不能和已经连接的 ...
随机推荐
- BZOJ3672: [Noi2014]购票(dp 斜率优化 点分治 二分 凸包)
题意 题目链接 Sol 介绍一种神奇的点分治的做法 啥?这都有根树了怎么点分治?? 嘿嘿,这道题的点分治不同于一般的点分治.正常的点分治思路大概是先统计过重心的,再递归下去 实际上一般的点分治与统计顺 ...
- 【c++错误】类的语法错误 error c2533:constructors not allowed a return type(构造函数不允许返回一个类型)
今天编写类的程序的时候不小心把类后的分号忘写了,就出现上面的错误提示. 顺便复习下类的正确格式: class 类名 { public: //习惯上将公有类型放在前面,便于阅读 ……(外部接口) pro ...
- 漂亮的ActionBar效果
Newsstand—这个应用引进了新的方式,使得ActionBar达到了新的水平.如果你打开这个应用的发布页,你会注意到不带图标的ActionBar是半透明的,而且和一个大的图片集(一个大的杂志图标, ...
- windows 设置CapsLock键开启大写后使用shift键取消大写
1.打开控制面板——>时钟.语言和区域——>更改键盘或其它输入法——>更改键盘——>高级键设置——>要关闭Caps Lock 2.ok
- apache ftp server的简单入门(properties验证)
Apache FTPServer:(开源) Apache FTPServer是一个100%纯Java的FTP服务器. 它的设计是基于现有的开放式协议的完整和便携式FTP服务器引擎解决方案.FTPSer ...
- asp.net(C#)常用时间日期处理类
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- winform listbox 使用DrawMode使用OwnerDrawVarialbe或OwnerDrawFixed无水平滚动条
因为需要使用DrawMode自行DrawItem,所以需要将DrawMode设置为OwnerDrawVarialbe或OwnerDrawFixed模式,代码如下: private void listB ...
- 使用 Azure 门户创建 Linux 虚拟机
可以通过 Azure 门户创建 Azure 虚拟机. 此方法提供一个基于浏览器的用户界面,用于创建和配置虚拟机和所有相关的资源. 本快速入门介绍了如何创建虚拟机并在 VM 上安装 webserver. ...
- sql server 查询ntext字段长度
DATALENGTH 返回任何表达式所占用的字节数. 语法 DATALENGTH ( expression ) 参数 expression 任何类型的表达式. 返回类型 int 注释 DATALENG ...
- ASP.NET MVC实现通用设置
网站中的设置实现方式有好几种,其中有将设置类序列化然后保存到文件中(例如使用XML序列化然后以XML形式保存在文件中),或者将设置信息保存到数据库中. 保存到数据库中的方式就是将设置的项作为key,设 ...