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个点(一个凸多边形的顶点),每次可以连接一个平面上的两个点(不能和已经连接的 ...
随机推荐
- css-图文案例
效果如下: 附上代码: <html> <head> <title>World</title> <style type="text/css ...
- 1000! mod 10^250
1000! mod 10^250 =============== the answer is 2 ================ Hi I'm trying to solve the above ...
- Android实现不同Active页面间的跳转
Intent intent = new Intent(); intent.setClass(ErrorPageActive.this, LoginActive.class); startActivit ...
- easyui 笔记
easyui-datagrid:loadFilter:处理服务器端传递过来的参数. 刷新datagrid:$("#xxx").datagrid('reload'): form 表单 ...
- 深入理解SVG坐标体系和transformations- viewport, viewBox,preserveAspectRatio
本文翻译自blog: https://www.sarasoueidan.com/blog/svg-coordinate-systems/ SVG元素不像其他HTML元素一样受css盒子模型所制约.这个 ...
- 使用 Azure CLI 管理 Azure 虚拟网络和 Linux 虚拟机
Azure 虚拟机使用 Azure 网络进行内部和外部网络通信. 本教程将指导读者部署两个虚拟机,并为这些 VM 配置 Azure 网络. 本教程中的示例假设 VM 将要托管包含数据库后端的 Web ...
- 转:C# WinForm窗体及其控件的自适应
一.说明 2012-11-30 曾经写过 <C# WinForm窗体及其控件自适应各种屏幕分辨率> ,其中也讲解了控件自适应的原理.近期有网友说,装在panel里面的控件,没有效果? 这 ...
- [翻译] CoreImage-with-EAGLContext
CoreImage-with-EAGLContext https://github.com/anaglik/CoreImage-with-EAGLContext Simple example of d ...
- Linux bzip2命令详解
Linux bzip/bunzip2命令是.bz2文件的解压缩程序. bunzip2可解压缩.bz2格式的压缩文件.bunzip2实际上是bzip2的符号连接,执行bunzip2与bzip2 -d的效 ...
- eclipse缓慢了么?
我的eclipse突然变得无比缓慢,javaw.exe的cpu使用率高达85%! 可是我什么也没做啊.项目组的其他同事询问过后,也没有谁修改了eclipse的配置文件(.setting文件夹 .cl ...