A Funny Game

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6178   Accepted: 3861

Description

Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least one coin must be removed. Players alternate moves with Alice starting. The player that removes the last coin wins. (The last player to move wins. If you can't move, you lose.) 
 
Figure 1
Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)

Suppose that both Alice and Bob do their best in the game. 
You are to write a program to determine who will finally win the game.

Input

There are several test cases. Each test case has only one line, which contains a positive integer n (1 <= n <= 106). There are no blank lines between cases. A line with a single 0 terminates the input. 

Output

For each test case, if Alice win the game,output "Alice", otherwise output "Bob". 

Sample Input

1
2
3
0

Sample Output

Alice
Alice
Bob

Source

POJ Contest,Author:Mathematica@ZSU
 
题意:每人每次可以取一个或两个连续的硬币,硬币之间有空位视作不连续。取完最后一个硬币的人获胜。问先手必胜还是后手必胜。
思路:n<=2时,先手必胜。n>2时,后手以中心对称模仿先手,必胜。
 //2017-10-26
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int main()
{
int n;
while(cin>>n && n){
if(n <= )cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
} return ;
}
 import java.util.*;

 public class Main{
public static void main(String args[]){
int n;
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
n = cin.nextInt();
if(n == 0)break;
if(n <= 2)System.out.println("Alice");
else System.out.println("Bob");
}
}
}

POJ2484的更多相关文章

  1. POJ2484 A Funny Game[博弈论]

    A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5401   Accepted: 3381 Desc ...

  2. [poj2484]A Funny Game(对称博弈)

    题目:http://poj.org/problem?id=2484 题意:n个石子围成一个圈,两个人轮流取,每次可以取一个石子或者相邻的两个石子,问先手胜还是后手胜 分析: 典型的对称博弈 如果n&g ...

  3. [POJ2484]A Funny Game

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4533   Accepted: 2780 Description Alice ...

  4. 【博弈论】poj2484 A Funny Game

    如果当前状态可以根据某条轴线把硬币分成两个相同的组,则当前状态是必败态. 因为不论在其中一组我们采取任何策略,对方都可以采取相同的策略,如此循环,对方必然抽走最后一枚硬币. 因为我们先手,因此抽完后盘 ...

  5. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  6. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  7. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

随机推荐

  1. python写的压缩软件

    import tkinterimport tkinter.filedialogimport osimport zipfileimport tkinter.messagebox #创建住窗口root = ...

  2. Day10:html和css

    Day10:html和css <html> <body> <h1>标题</h1> <p>段落</p> </body> ...

  3. 第62节:探索Java中的网络编程技术

    前言 感谢! 承蒙关照~ 探索Java中的网络编程技术 网络编程就是io技术和网络技术的结合,网络模型的定义,只要共用网络模型就可以两者连接.网络模型参考. 一座塔有七层,我们需要闯关. 第一层物理层 ...

  4. API接口开发(持续更新)

    1. 接口调用失败时的处理方式 接口调用失败时分为 请求失败和业务失败. 请求失败的相关信息可通过HTTP状态码体现出来, 业务失败的相关信息需要在返回数据中体现出来. 2. 分页查询 批量查询时需要 ...

  5. Python档案袋(脚本执行和输入输出)

    脚本的执行: 1.执行时确定解释器为Python3 python3 脚本名 2.在代码开始行确定解释器为Python3,与shell相似 env命令表示全局搜索Python3解释器 #!/usr/bi ...

  6. node-sqlite3 学习笔记

    * 使用sqlite3持久化数据 * 需求:把一个数组中的每个对象,每个对象中的属性,存到xxx.db文件中去,像数据库一样的去操作它 * 功能:1. 创建数据库(数据库存在的话,那就直接打开) * ...

  7. 十大经典排序算法(python实现)(原创)

    个人最喜欢的排序方法是非比较类的计数排序,简单粗暴.专治花里胡哨!!! 使用场景: 1,空间复杂度 越低越好.n值较大: 堆排序 O(nlog2n) O(1) 2,无空间复杂度要求.n值较大: 桶排序 ...

  8. Google Chrome 书签导出并生成 MHTML 文件

    目的 因为某些原因需要将存放在 Google Chrome 内的书签导出到本地,所幸 Google Chrome 提供了导出书签的功能. 分析 首先在 Google Chrome 浏览器当中输入 ch ...

  9. Flume的各种类型的组件介绍

    1.   Source NetCat Source:绑定的端口(tcp.udp),将流经端口的每一个文本行数据作为Event输入: type:source的类型,必须是netcat. bind:要监听 ...

  10. Go语言下的线程模型

    阅读Go并发编程对go语言线程模型的笔记,解释的非常到,好记性不如烂笔头,忘记的时候回来翻一番,在此做下笔记. Go语言的线程实现模型,又3个必知的核心元素,他们支撑起了这个线程实现模型的主要框架: ...