链接:

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. Variational Auto-encoder(VAE)变分自编码器-Pytorch

    import os import torch import torch.nn as nn import torch.nn.functional as F import torchvision from ...

  2. @Scheduled注解各参数详解

    @Scheduled注解各参数详解 @Scheduled注解的使用可以参考这个:https://www.cnblogs.com/mengw/p/11564338.html 参数详解 1. cron 该 ...

  3. Smart3D飞控&地方坐标系

    资源 ContextCapture(原Smart3D)教程 | Wish3D 航测数据处理答疑55问!涉及CC.Pix4D.Photoscan.EPS等常见软件问题_云进行 飞控软件 Smart3D常 ...

  4. DG环境恢复同步遇到报错ORA-00353ORA-00334以及ORA-00600[2619], [47745]

    问题说明 客户环境主库4节点RAC11.2.0.4,单实例DG环境,DG由于空间不足,导致同步中断,由于DG备库未应用的归档主库都再,本次恢复的方式,是开启dg mrp进程,自动同步追上主库. 以下遇 ...

  5. 使用Jenkins编译打包SpringCloud微服务中的个别目录

    意义说明: 使用Jenkins从Gogs拉取SpringCloud微服务,拉取的是整个仓库的内容,分好多个模块文件夹,但是使用maven编译打包的话只编译打包指定的模块文件夹 Gogs Webhook ...

  6. 遗传算法python实现

    最近看了一下遗传算法,使用轮盘赌选择染色体,使用单点交叉,下面是代码实现(python3) import numpy as np import random from scipy.optimize i ...

  7. springboot_3

    1. 返回数据与返回页面 在写web项目的时候,controller里的返回值一般分为两种,一种是返回页面,也就是ModeAndView,另一种是直接返回数据,比如json格式的数据. 返回一个页面, ...

  8. C#避免WinForm窗体假死

    WinForm窗体在使用过程中如果因为程序等待时间太久而导致窗体本身假死无法控制,会严重影响用户的体验,这种情况大多是UI线程被耗时长的代码操作占用所致,可以新开一个线程用来完成耗时长的操作,然后再将 ...

  9. log4net SmtpAppender 踩坑总结

    错误集合: System.Net.Mail.SmtpException: 命令顺序不正确. 服务器响应为:Error: need EHLO and AUTH first ! System.Net.Ma ...

  10. JAVA操作ORACLE大对象

    一:操作CLOB  (1)数据库表结构如下:         create table CLOB_TEST      (         ID      VARCHAR2(5) not null,   ...