zoukankan      html  css  js  c++  java
  • 【1020 A Childhood Game(简单博弈论)】

    1020 - A Childhood Game
    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
    Developed and Maintained by 
    JANE ALAM JAN
    Copyright © 2012 
    LightOJ, Jane Alam Jan
     
     
     
     
     
     
     
     1 // Project name : 1020 ( A Childhood Game ) 
     2 // File name    : main.cpp
     3 // Author       : iCoding
     4 // E-mail       : honi.linux@gmail.com
     5 // Date & Time  : Sat Aug 11 13:45:21 2012
     6 
     7 
     8 #include <iostream>
     9 #include <stdio.h>
    10 #include <string>
    11 #include <cmath>
    12 #include <algorithm>
    13 using namespace std;
    14 
    15 /*************************************************************************************/
    16 /* data */
    17 const string Alice = "Alice";
    18 const string Bob   = "Bob"  ;
    19 
    20 /*************************************************************************************/
    21 /* procedure */
    22 
    23 
    24 /*************************************************************************************/
    25 /* main */
    26 int main()
    27 {
    28     int iT;
    29     cin >> iT;
    30     for (int iCaseCount = 1; iCaseCount <= iT; iCaseCount++)
    31     {
    32         int iNum;
    33         string iStarter;
    34         printf("Case %d: ", iCaseCount);
    35         cin >> iNum >> iStarter;
    36         if (iStarter == Bob)
    37         {
    38             /* If Bob starts first, then the player who takes the last marble wins the game. */
    39             if (iNum % 3 == 0)
    40             {
    41                 cout << Alice << endl;
    42             }
    43             else
    44             {
    45                 cout << Bob << endl;
    46             }
    47         }
    48         else
    49         {
    50             /* If Alice starts first, then the player who takes the last marble looses the game. */
    51             if ((iNum-1) % 3 == 0)
    52             {
    53                 cout << Bob << endl;
    54             }
    55             else
    56             {
    57                 cout << Alice << endl;
    58             }
    59         }
    60     }
    61     return 0;
    62 }
    63 
    64 // end 
    65 // Code by Sublime text 2
    66 // iCoding@CodeLab 
  • 相关阅读:
    oracle 判断字符串是否包含指定内容
    java 如何使用多线程调用类的静态方法?
    oracle 快速复制表结构、表数据
    oracle 清空表数据的2种方式及速度比较
    一、Instrument之Core Animation工具
    net登录积分(每天登录积分仅仅能加一次) 时间的比較
    正规方程 Normal Equation
    笑谈贝叶斯网络(干货)上
    SQL SERVER 面试题
    好的创始人想要改变世界,最好的创始人还要不放弃——扎克伯格清华中文演讲
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2633591.html
Copyright © 2011-2022 走看看