B - B

Crawling in process... Crawling failed Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Time Limit:1000ms Memory Limit:65536KB
Description
   Nim is a game in which two players take turns removing stones from heaps. On each
turn, a player must choose a single heap and remove one or more stones from that
heap. The player who takes the last stone wins. Alice and Bob are bored with
playing Nim over and over again, so they've decided to create a new variation
called Ordered Nim.
Ordered Nim differs from regular Nim in the following way.
The heaps are numbered 0 through n-1 (where n is the number of heaps), and a
player can only remove stones from a heap if all the lower-numbered heaps are
empty. You are given n interger(s), where the i-th interger(0-indexed) is the
number of stones in heap i at the beginning of the game. Alice will take the
first turn.
Determine who will win the game, assuming both players play
optimally.
Input

    input consist of multiple cases;process till EOF.
each case contain two lines.
on the first line is a interger n (1<=n<=50).
the next line contain n interger(s),each of which will be between 1 and 1000000000,inclusive.
Output

    for each case output one line .
if Alice can win print "Alice".
otherwise print "Bob".
Sample Input

1
5
2
1 2
Sample Output

Alice
Bob
Hint


Source

srm450
#include<cstdio>
int main()
{
int n;
while(scanf("%d",&n)!=-1)
{
int cnt=0,leap=0,k;
//查找序列中第一个大于1的数t,谁拥有这个数的主动权谁就赢
for(int i=1; i<=n; i++)
{
scanf("%d",&k);
if(k>1) leap=1;
if(!leap) cnt++;
}
//如果t前面的1的个数为奇数&&该序列不全为1(leap==1),Bob有主动权
if(cnt%2==1&&leap) printf("Bob\n");
else if(cnt%2==0&&leap) printf("Alice\n");//如果t前面的1的个数为偶数&&该序列不全为1(leap==1),Alice有主动权
else
{
//该序列全为1
if(n%2==0) printf("Bob\n");
else printf("Alice\n");
} }
return 0;
}
//为什么按顺序遇到第一堆大于1的可以决定胜利??
/*举例子 1 2 1 1 2 1 1 第一堆大于1的数是 2 ,序列看成 1 2(1 1 2 1 1)
若先取得(1 1 2 1 1)的胜利,那么由于 2 那堆由Bob得到主动权,那么Bob可以先取一个
留剩一个给Alice取,那么就可使得Bob先取剩下的所有(1 1 2 1 1),由假设,Bob胜利 若先取得(1 1 2 1 1)的输,那么Bob可以把该堆全部取完,Alice先取(1 1 2 1 1)输,即Bob赢
所以,不管先取剩下的是输是赢,Bob都会赢 当序列全为1时,按正常取

  

寒假D1 B的更多相关文章

  1. (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest

    layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest author: "luow ...

  2. [NOIP2016]换教室 D1 T3 Floyed+期望DP

    [NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...

  3. 寒假学习计划(c++作业2)

    C++学习计划 一.课程概况 1.课程名称:c++远征攻略 2.授课人姓名:james_yuan 3.课程链接地址:http://www.imooc.com/course/programdetail/ ...

  4. Q114寒假作业之割绳子

    割绳子 TimeLimit:1000MS  MemoryLimit:10000K 64-bit integer IO format:%lld Problem Description 已知有n条绳子,每 ...

  5. [GRYZ]寒假模拟赛

    写在前面 这是首次广饶一中的OIERS自编自导,自出自做(zuo)的模拟赛. 鉴于水平气压比较低,机(wei)智(suo)的WMY/XYD/HYXZC就上网FQ下海找了不少水(fei)题,经过他们优( ...

  6. 寒假挑战PythonTip(一人一python)总结——算法是程序的灵魂,程序员的心法

        2014年2月中旬,我上升到挑战python英雄榜第3名.这是我寒假修炼算法的成果之一.来一下总结吧! Linux的创始人Linus Torvalds在一次演讲中有一段涉及“什么才是优秀程序员 ...

  7. Codeforces Round #350 (Div. 2)A,B,C,D1

    A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  8. Acdream1084 寒假安排 求n!中v因子个数

    题目链接:pid=1084">点击打开链接 寒假安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 ...

  9. V3学院XILINX FPGA寒假班培训感受 江苏大学 电子信息科学与技术 邓普建

    事先申明一点,我是大一的学生,因此会站在一个新生的角度叙述. 刚开始接触V3学院是在江苏大学与V3学院合办的FPGA/SOC培训中,那是对全校开放的免费培训,历时三个周末.我那时有幸从头听到了尾,觉得 ...

随机推荐

  1. ADF成长记1--认识ADF

    2014-07-08 近段时间由于公司项目需要,开始接触Oracle ADF.都说有事没事,上百度,但是对于IT技术而言,上百度还真是不一定好使,至于谷歌嘛,很不巧的进不去了.不过网上ADF的资料当真 ...

  2. ext3文件系统反删除利器-ext3grep

    导读 Linux作为企业级服务器,数据的安全性至关重要,任何数据德尔丢失和误删都是不可容忍的!最近我接触到一款软件-ext3grep,它可以恢复误删的数据,下面简单讲解一下这个软件. ext3grep ...

  3. 采用Unity快速开发高质量游戏的若干优化建议

    http://files.cnblogs.com/123ing/%E9%87%87%E7%94%A8Unity%E5%BF%AB%E9%80%9F%E5%BC%80%E5%8F%91%E9%AB%98 ...

  4. HDU 1713 最小公倍数与最大公约数的问题 相遇周期

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) 相遇周期 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/ ...

  5. 组合数学or not ---- n选k有重

    模板问题: 1. 取物品 (comb.pas/c/cpp) [问题描述] 现在有n个物品(有可能相同),请您编程计算从中取k个有多少种不同的取法.[输入] 输入文件有两行,第一行包含两个整数n,k(2 ...

  6. Java字符串split函数的注意事项

    Java字符串的split方法可以分割字符串,但和其他语言不太一样,split方法的参数不是单个字符,而是正则表达式,如果输入了竖线(|)这样的字符作为分割字符串,会出现意想不到的结果, 如, Str ...

  7. location 、history

    location.href= location.reload() history.go()  0   1  -1 history.back() history.forward() history.le ...

  8. 在windows下用cygwin和eclipse搭建cocos2dx(2.1.4)的android开发环

    一.准备工作 需要下载和安装以下内容,请根据自己的操作系统选择x86和x64(我的是64位win7,我就拿64位说事) 1.jdk-7u25-windows-x64.exe(下载完后直接安装,一直下一 ...

  9. 57. 数对之差的最大值:4种方法详解与总结[maximum difference of array]

    [本文链接] http://www.cnblogs.com/hellogiser/p/maximum-difference-of-array.html [题目] 在数组中,数字减去它右边的数字得到一个 ...

  10. 网络流-最大流 模板(poj 1273)

    #include<cstdio> #include<iostream> #include<cstring> #include<queue> #defin ...