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. Rescue

    1039: Rescue Time Limit: 1 Sec  Memory Limit: 32 MBSubmit: 1320  Solved: 306 Description Angel was c ...

  2. shell截取字符串

    image_tag="pangu-20151021102145\"" 1.用#号截取,符号-右面所有字符串 TMP=${image_tag#*-} echo $TMP 得 ...

  3. QEMU-KVM中的多线程压缩迁移技术

    导读 目前的迁移技术,都是通过向QEMUFILE中直接写入裸内存数据来达到传送虚拟机的目的端,这种情况下,发送的数据量大,从而会导致更高的迁移时间(total time)和黑宕时间(downtime) ...

  4. request-log-analyzer日志分析

    (这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 日志分析是常见的工作,方法如下: 使用工具:request-log-analyzer安装:$ ...

  5. HDU3345广搜 (P,E,T,#)

    War chess is hh's favorite game:In this game, there is an N * M battle map, and every player has his ...

  6. HDOJ 1878 欧拉回路 nyoj 42一笔画问题

    #include<cstdio> #include<cstring> ]; int find(int x) { if(visited[x]!=x) return find(vi ...

  7. awk内置字符串函数 awk 格式化输出

    i249 ~ # ps -efl|head -1|awk '$2~/S/{print $2}'Si249 ~ # ps -efl|awk '$2~/S/{print $2}'SSSS printf - ...

  8. 【持续集成】[Jenkins]Job中如何传递自定义变量

    [Jenkins]Job中如何传递自定义变量 来自dweiwei   2015-06-27 18:37:19|  分类: 自动化测试 |举报 |字号大中小 订阅 用微信  “扫一扫” 将文章分享到朋友 ...

  9. Effecvtive C++笔记:让自己习惯C++

    条款01:视C++为一个语言联绑 C++的四个语言层次: C:C++是以C为基础的.基本数据类型.语句.预处理器.数组.指针等统统来自C. Oject-Oriented C++:面向对象这一特性包含了 ...

  10. 3.子数组的最大和[MaximumContinuousSubArray]

    [题目]: 输入一个整形数组,数组里有正数也有负数.数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和.求所有子数组的和的最大值,要求时间复杂度为O(n). 例如输入的数组为1, -2, ...