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. 关于Tabula FPGA的话题 (转)

    最近关注了一下Tabula的产品,特别是这个公司的FPGA.我的关注源于Intel对Tabula的支持.最近和在FPGA方面有较深理解的几位人士简单聊了聊,以下是这次对话的主要内容,希望能对从事这方面 ...

  2. Java中的封装

    在前面的一些日子里,一只都在学习C#语言,使用C#在做一些小项目的,今天转到了Java的学习,还是感觉有点的不习惯,没有以前的中文界面的,全是英文.写起代码来都一直保持着C#中的编码的习惯,但是学习J ...

  3. java笔记--反射进阶之总结与详解

    一.反射进阶之动态设置类的私有域 "封装"是Java的三大特性之一,为了能更好保证其封装性,我们往往需要将域设置成私有的, 然后通过提供相对应的set和get方法来操作这个域.但是 ...

  4. Objective-C和其他C指针的转换

    首先看一下典型的NSString与CFStringRef的相互转换   http://www.tuicool.com/articles/MJRr226 // CFStringRef to NSStri ...

  5. Phpstorm常用设置

    Phpstorm更换主题和字体 1.File -- settings -- Editor -- Colors And Fonts: 2.在右侧窗口中选择Scheme name : 选择一个自己喜欢的主 ...

  6. linux 查看系统信息命令(比较全)

    linux 查看系统信息命令是linux初学者必备的基础知识, 这些命令也非常有用, 因为进入linux第一件事就可能是首先查看系统信息, 因此必要的系统的学习一下这些linux系统信息命令还是非常有 ...

  7. HDOJ 3790

    dijstra最短路径算法 : 9885560 2013-12-23 23:54:56 Accepted 3790 203MS 8112K 1343 B C++ 泽泽 #include<cstd ...

  8. apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))

    apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))   今天用apache 自带的ab工具测试,当并发量达到1000多的时 ...

  9. 【Linux】为啥查某个进程的线程,查出来的所有线程的pid不一样啊

    楼上说的linux线程和进程是一样的,这个说法是错误的. 看了楼主的问题,感觉楼主是被PID给弄混了,线程进程都会有自己的ID,这个ID就叫做PID,PID是不特指进程ID,线程ID也可以叫做PID. ...

  10. Longest Consecutive Sequence

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. C ...