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. Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable

    原文:http://blog.csdn.net/abcjennifer/article/details/7700772 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  2. ubuntu 快速安装jre

    sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-i ...

  3. java常见异常集锦

    1. java.lang.nullpointerexception 这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对 ...

  4. [官方教程] [ES4封装教程]2.使用 Easy Sysprep v4 封装 Windows XP

    (一)备份当前操作系统封装的第一步,其实是备份当前安装好的操作系统.避免我们在之后的步骤中出现问题,以至于还要重新安装操作系统,浪费时间精力.系统备份想必大家都会.对于WinXP而言,建议使用Ghos ...

  5. HDOJ 2546饭卡(01背包问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如 ...

  6. C 结构体小结

    看了三天结构体,是时候总结一下了. 关于结构体的声明: struct Student { ]; char sex; int age; ]; }; /*然后定义一个Student 类型的 student ...

  7. Java锁之自旋锁详解

    锁作为并发共享数据,保证一致性的工具,在JAVA平台有多种实现(如 synchronized 和 ReentrantLock等等 ) .这些已经写好提供的锁为我们开发提供了便利,但是锁的具体性质以及类 ...

  8. Android ViewPager轮播图

    Android客户端开发中很多时候需要用到轮播图的方式进行重点新闻的推送或者欢迎页面的制作,下面这个轮播图效果的Deamo来自互联网再经过修改而成. 1.布局文件activity_main.xml中添 ...

  9. Android 中的code sign

    Android 中和ios中都有code sign.它们的目的一样,都是要保证程序的可靠性,最基本实现原理也一样.但是sign的过程比较不同. 下面记录一点Android sign的重要知识. 请参看 ...

  10. codeforces 479C Exams 解题报告

    题目链接:http://codeforces.com/problemset/problem/479/C 题目意思:简单来说,就是有个人需要通过 n 门考试,每场考试他可以选择ai, bi 这其中一个时 ...