LightOj 1020 博弈
来源:互联网 发布:远程端口是什么 编辑:程序博客网 时间:2024/06/07 06:24
思路介绍:
1. 如果首先由Alice取,定义ans[i],如果ans[i]=1表示Alice会取胜,反之Bob取胜。枚举前100项,ans[1]=0,ans[2]=1,ans[i]=!(ans[i-1]&&ans[i-2]);
可以发现规律:当i为2,3,5,6,8,9....时Alice取胜,所以Alice取胜的条件为:i%3!=1;
2.如果Bob先取,ans[1]=1,ans[2]=1,ans[i]=!(ans[i-1]&&ans[i-2])
规律:当i为1,2,4,5,7,8...时Bob取胜,、;所以Bob取胜的条件为:i%3!=0;
1020 - A Childhood Game
PDF (English) Statistics Forum
Time Limit: 0.5 second(s) Memory Limit: 32 MB
Alice and Bob are playing a game with marbles; you may have played this game in childhood. The game is playing by alternating turns. In each turn a player can take exactly one or two marbles.
Both Alice and Bob know the number of marbles initially. Now the game can be started by any one. But the winning condition depends on the player who starts it. If Alice starts first, then the player who takes the last marble looses the game. If Bob starts first, then the player who takes the last marble wins the game.
Now you are given the initial number of marbles and the name of the player who starts first. Then you have to find the winner of the game if both of them play optimally.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n < 231) and the name of the player who starts first.
Output
For each case, print the case number and the name of the winning player.
Sample Input
Output for Sample Input
3
1 Alice
2 Alice
3 Bob
Case 1: Bob
Case 2: Alice
Case 3: Alice
PROBLEM SETTER: JANE ALAM JAN
<span style="color:#6600cc;">/************************************** author : Grant Yuan time : 2014/8/20 13:38 algorithm: 博弈 source : LightOj 1020***************************************/#include<bits/stdc++.h>#define Alice "Alice"#define Bob "Bob"using namespace std;char s[6];int n,t;int main(){ scanf("%d",&t); for(int i=1;i<=t;i++) { memset(s,0,sizeof(s)); scanf("%d%s",&n,s); printf("Case %d: ",i); if(strcmp(s,Alice)==0){ if(n%3==1){ printf("Bob\n"); } else{ printf("Alice\n"); } } else{ if(n%3==0){ printf("Alice\n"); } else{ printf("Bob\n"); } } } /*ans[1]=false;ans[2]=true; for(int i=3;i<=100;i++) { ans[i]=true; if(ans[i-1]&&ans[i-2]) ans[i]=false; } for(int i=1;i<=100;i++) { printf("%d ",i); if(ans[i]) printf("1\n"); else printf("0\n"); }*/ return 0;}</span>
- lightoj 1020 (博弈)
- LightOj 1020 博弈
- lightoj 1020 水博弈
- lightoj 1020 - A Childhood Game 【博弈】
- lightoj 1020 - A Childhood Game 简单博弈
- LightOJ-1031 博弈 区间DP
- 【lightOJ】 Partitioning Game (博弈,sg函数)
- 【lightOJ】 Again Stone Game (博弈,SG函数)
- lightoj 1186 - Incredible Chess Nim博弈
- lightoj 1192 - Left Right Nim博弈
- lightoj 1247 - Matrix Game Nim博弈
- lightoj 1253 - Misere Nim Nim博弈
- nim博弈_______Crazy Calendar( lightoj 1393 )
- lightoj 1031 Easy Game (区间dp 博弈)
- A - Matrix Game(nim 博弈)LightOJ 1247
- lightoj 1031 - Easy Game 博弈类区间DP
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
- LightOJ-1253 Misere Nim(Nim求解不正常的博弈)
- 如何学好C语言
- js四舍五入保留几位小数,整数部分每3位用逗号隔开
- eclipse搭建php-XDebug调试环境
- C++,rand,srand随机数
- 图 - 生成树和最小生成树 - 最小生成树
- LightOj 1020 博弈
- 如何学好C++语言
- [4] 算法之路 - 插入排序之Shell间隔与Sedgewick间隔
- How to install MySQL Server 5.6 on CentOS 7 / RHEL 7
- 《windows核心编程系列》谈谈windows线程栈
- C++程序设计之四书五经(上篇)
- unity3d ios平台优化图形性能
- Java移位操作符
- C++程序设计之四书五经(下篇)