链接:

https://vjudge.net/problem/LightOJ-1020

题意:

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.

思路:

考虑最后拿输,则2,3都是必赢,得到n%3 == 1先手输。

最后拿赢,则1,2必赢,n%3 == 0先手输。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector> using namespace std;
typedef long long LL;
const int INF = 1e9; const int MAXN = 1e6+10;
const int MOD = 1e9+7; int main()
{
int t, cnt = 0;
LL n;
char s[10];
scanf("%d", &t);
while(t--)
{
scanf("%lld%s", &n, s);
printf("Case %d: ", ++cnt);
if (s[0] == 'A')
{
if (n%3 == 1)
puts("Bob");
else
puts("Alice");
}
else
{
if (n%3 == 0)
puts("Alice");
else
puts("Bob");
}
} return 0;
}

LightOJ-1020-A Childhood Game(博弈)的更多相关文章

  1. Lightoj 1020 - A Childhood Game (博弈)

    题目链接: 1020 - A Childhood Game 题目描述: Alice和Bob在玩弹珠游戏,两人轮流拿走弹珠,每次只能拿走一个或者两个,当Alice作为先手时谁拿走最后一个就是输家,而Bo ...

  2. Lightoj 1020 - A Childhood Game

    Allice先拿,最后拿球的输. Bob先拿,最后拿球的赢. 考虑Alice先拿球,当n=1时 Alice输  记dp[1]=0; n=2,  dp[2]=1 n=3,  dp[3]=1 因为n=1, ...

  3. lightoj 1020 (博弈水题)

    lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...

  4. lightoj 1020 (博弈)

    思路:很简单的博弈,找出每个人先拿的必胜态进行状态转移即可. #include<cstdio> #include<string> #include<cstring> ...

  5. LightOJ 1186 Icreable Chess(Nim博弈)

    You are given an n x n chess board. Only pawn is used in the 'Incredible Chess' and they can move fo ...

  6. LightOJ 1393 Crazy Calendar(博弈)题解

    题意:r*c方格中,每个格子有一定石子,每次移动每格任意数量石子,只能向下或者向右动一格,不能移动为败 思路:显然是Nim,到右下曼哈顿距离为偶数的不用管,因为先手动一下后手动一下最后移到右下后还是先 ...

  7. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  8. LightOJ 1247 Matrix Game (尼姆博弈)

    A - Matrix Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submi ...

  9. LightOJ - 1247 Matrix Game (Nim博弈)题解

    题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...

  10. LightOJ 1355 :Game of CS(树上green博弈)

    Jolly and Emily are two bees studying in Computer Science. Unlike other bees they are fond of playin ...

随机推荐

  1. Java基础---Java 类

    类 成员变量直接定义在类里面,在方法的外面: 成员方法不要写static关键字 eg: public class Student { String name; // 成员变量 int aeg; //成 ...

  2. mysql 添加大量测试数据

    mysql 添加大量测试数据 场景 针对于大量测试数据插入,检测sql执行速度 第一步:建表 // 测试表 CREATE TABLE user ( id int(11) NOT NULL AUTO_I ...

  3. redis数据库——python使用和django中使用

    为什么要学redis 1.redis是内存 no-sql 数据库,相比mysql等硬盘数据库效率高 2.在内存值配置数据库使用,而不直接使用内存,redis存储的数据是可以管理的 3.memcache ...

  4. flannel overlay网络浅析

    Flannel基于UDP的网络实现 container-1的route表信息如下(b1): default via 100.96.1.1 dev eth0 100.96.1.0/24 dev eth0 ...

  5. WUSTOJ 1302: 区间k大数查询(Java)

    题目链接:

  6. Fiddler讲解3

    想要 浏览更多Fiddler内容:请点击进入Fiddler官方文档 阅读目录: 一.Fiddler自定义请求: 二.Fiddler修改请求: 三.减少期望的延迟:100个继续标题: 四.重命名无效的P ...

  7. Generator 实现

    Generator 是 ES6 中新增的语法,和 Promise 一样,都可以用来异步编程 // 使用 * 表示这是一个 Generator 函数 // 内部可以通过 yield 暂停代码 // 通过 ...

  8. Golang高阶:Golang1.5到Golang1.12包管理

    Golang1.5到Golang1.12包管理 1. 前言 Golang 是一门到如今有十年的静态高级语言了,2009年的时候算是正式推出了,然后到最近的一两年,2017-2018年的时候,突然直线上 ...

  9. 递推问题 hdu 2046 与1143的比对

    2046 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:   Input 输入数据由多行组成,每行 ...

  10. url格式化函数http_build_query() 和parse_str() 函数

    例子 1. http_build_query() 使用示例 <?php $data = array('foo'=>'bar', 'baz'=>'boom', 'cow'=>'m ...