1349: Taking Pebbles (博弈 打表找规律)
1349: Taking Pebbles
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.
Hint
Source
中南大学第一届长沙地区程序设计邀请赛一般都是打个表,找找看有没有规律
因为答案就两种情况
肯定是跟n有关
那可能是有规律的......
试着打个表
果然!!!!!
n为以下数字的时候
2
5
11
23
47
95
191
383
767
Bob赢
找到这个规律之后
还pe,re了好几发
因为还想着把表存下来....
真是傻得一批
直接判断一下不是不是这些数字就可以了啊
.....
void dabiao() { f[1]=1; f[2]=0; for(int i=3; i<=1000; i++) { int flag=0; int x=i/2; if(i%2) x=i/2+1; for(int j=i-1; j>=x; j--) { if(f[j]==0) { flag=1; break; } } if(flag==1) { f[i]=1; } } for(int i=1; i<=1000; i++) { if(f[i]==0) { 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%2==0&&n!=2) printf("Alice\n"); else if(n==2) printf("Bob\n"); else { int k=2; while(k<n) { k=k*2+1; } if(k==n) printf("Bob\n"); else printf("Alice\n"); } } return 0; } /* 碰到这种题就有点郁闷,因为写的很少 一般都是打个表,找找看有没有规律 因为答案就两种情况 肯定是跟n有关 那可能是有规律的...... 试着打个表 果然!!!!! n为以下数字的时候 2 5 11 23 47 95 191 383 767 Bob赢 找到这个规律之后 还pe,re了好几发 因为还想着把表存下来.... 真是傻得一批 直接判断一下不是不是这些数字就可以了啊 ..... */ /* 2 5 11 23 47 95 191 383 767 */
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南