热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

寒假B

B-BCrawlinginprocessCrawlingfailedTimeLimit:0MSMemoryLimit:0KB64bitIOFormat:%lld&%lluSu


B - B

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



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
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时,按正常取

  





推荐阅读
  • #includestdafx.h#includeiostream#includesstream#includemap#includestring ... [详细]
  • 第38天:Python decimal 模块
    by程序员野客在我们开发工作中浮点类型的使用还是比较普遍的,对于一些涉及资金金额的计算更是不能有丝毫误差,Python的decimal模块为浮点型精确计算提供了支持。1简介deci ... [详细]
  • 法国人家喻户晓的一首歌,很老的一首了。旋律轻盈,歌词温馨会把你带回到小时候的回忆中去。Ilrevientàmamémoire一切都回到我脑海中Dessouvenirsfamilie ... [详细]
  • CentOS 7.6网卡绑定mode1
    CentOS7.6网卡绑定mode1[root@server~]#systemctlstopNetworkManager[root@server~]#systemctldisabl ... [详细]
  • PythonDay3
    #Author:ZhaoBin#实现对Haproxy配置文件的增删改查deffetch(backend):result[]withopen('ha.conf',&# ... [详细]
  • webpack 配置IP 和端口号
    最近在用webpack搭建本地服务器的时候,因为不想总是用localhost来跑,所以对webpack.config.js进行了配置,如下devServer:{publicPath ... [详细]
  • 利用ipv6技术,废旧笔记本变成server
    如果你家的路由器已经get到了ipv6地址,并且你家的电脑也获取了有效的ipv6地址,在广域网的设备可以访问到。那恭喜你,再配合我这个dd ... [详细]
  • 题目:Givenanintegerarray,youneedtofindone continuoussubarray thatifyouonlysortthissubarrayin ... [详细]
  • SortalinkedlistinO(nlogn)timeusingconstantspacecomplexity.这道题属于人生中第一次对链表进行操作,首先,不同于C++中的st ... [详细]
  • Redis 外部访问设置
    1、错误原因Redis搭建好后一般都是使用编程语言进行连接调用,默认Redis的设置是不允许外界访问的,连接Redis只能通过本地(127.0.0.1)来连接,而不能使用网络IP( ... [详细]
  • 第一部分:TSqlTop有两种用法1,限制查询结果集返回的行数或总行数的百分比。当将TOP与ORDERBY子句结合使用时,结果集限制为前N个已排序行;否则,以未定义的顺序返回前N个 ... [详细]
  • socket8 [命名管道]
    ::命名管道不但能实现同一台机器上两个进程通信,还能在网络中不同机器上的两个进程之间的通信机制。与邮槽不同,命名管道是采用基于连接并且可靠的传输方式,所以命名管道传输数据只能一对一 ... [详细]
  • queue接口特点:可以模拟队列行为,即“先进先出”。接口结构queue接口继承了Collection接口,并增加了一些新方法12345678910111213141516publ ... [详细]
  • 1、对于List而言,要不然就使用迭代器,要不然就从后往前删除,从前往后删除会出现角标越界。因为我List有两个remove方法,一个是int作为形参(删除指定位置的元素),一个是 ... [详细]
  • Givens1,s2,s3,findwhethers3isformedbytheinterleavingofs1ands2.Forexample,Given:s1aabcc ... [详细]
author-avatar
初来乍到1231
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有