Alice and Bob

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1130 Accepted Submission(s): 407

Problem Description
Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that's why they feel bored again and again. They just invented a new game, as they usually did.

The rule of the new game is quite simple. At the beginning of the game, they write down N random positive integers, then they take turns (Alice first) to either:

1. Decrease a number by one.

2. Erase any two numbers and write down their sum.

Whenever a number is decreased to 0, it will be erased automatically. The game ends when all numbers are finally erased, and the one who cannot play in his(her) turn loses the game.

Here's the problem: Who will win the game if both use the best strategy? Find it out quickly, before they get bored of the game again!
 
Input
The first line contains an integer T(1 <= T <= 4000), indicating the number of test cases.

Each test case contains several lines.

The first line contains an integer N(1 <= N <= 50).

The next line contains N positive integers A
1 ....A
N(1 <= A
i <= 1000), represents the numbers they write down at the beginning of the game.
 
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is either "Alice" or "Bob".
 
Sample Input
3
3
1 1 2
2
3 4
3
2 3 5
 
Sample Output
Case #1: Alice
Case #2: Bob
Case #3: Bob
博弈,这题,对于是1的堆, 我们可以单独处理,而对于,其它的堆,我们直接加起来,比奇偶,用dp[i][j]表是有i个是1的堆,其它的堆合在一起,再比奇偶,最后,如果等于1就是先取的胜,否刚后取的胜,这样,我们发现,只有是1的堆才会影响最后的结果,如果,这个堆大于1,那个此时会胜的人,一定会,先把这些堆先合,最后再比奇偶,而要败的人,没有任何办法,此时,他就想办法,改变1的堆,因为合并1的堆,相当于操作两次,会变最后的结果,这样,所有的人,都要抢是1的堆,是1的堆,总共有4种操作,1:是直操拿是1的堆,2:合并1的堆到非1的堆,3取不是1的堆4:合并两个非1的堆 ,此时有两种情况,第一,全都是1,这时,只能加2不能合并到非1的堆,第二,有非1的堆,那么,两个1的堆加再合到一个非1的堆加3,这样全部都到位了!
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
int dp[55][60000];
int dfs(int n,int p){
if(dp[n][p]!=-1)return dp[n][p];
if(p==1)return dp[n][p]=dfs(n+1,0);
dp[n][p]=0;
if(n>0&&!dfs(n-1,p)) return dp[n][p]=1;
if(p>1&&!dfs(n,p-1)) return dp[n][p]=1;
if(n>0&&p&&!dfs(n-1,p+1)) return dp[n][p]=1;
if(n>=2&&((p&&!dfs(n-2,p+3))||(!p&&!dfs(n-2,2)))) return dp[n][p]=1;
return dp[n][p];
}
int main()
{
int tcase,n,i,pri,k,ans,tt=1;
mem(dp,-1);
scanf("%d",&tcase);
while(tcase--){
k=0;ans=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&pri);
if(pri==1)k++;
else ans+=pri+1;
}
if(ans)ans--;
printf("Case #%d: ",tt++);
if(dfs(k,ans))printf("Alice\n");
else printf("Bob\n");
}
return 0;
}

hdu4111 Alice and Bob的更多相关文章

  1. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  2. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

  3. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  4. sdutoj 2608 Alice and Bob

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...

  5. hdu 4268 Alice and Bob

    Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  6. 2014 Super Training #6 A Alice and Bob --SG函数

    原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...

  7. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

  8. 位运算 2013年山东省赛 F Alice and Bob

    题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...

  9. SDUT 2608:Alice and Bob

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...

随机推荐

  1. Hibernate的fetch

    hibernate抓取策略fetch具体解释一.hibernate抓取策略(单端代理的批量抓取fetch=select(默认)/join)測试用例:Student student = (Student ...

  2. C++中struct和class的区别 [转]

    一. C++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据类型的数据结构了,它已经获取了太多的功能. struct能包含成员函数吗?   能! struct能继承吗?  ...

  3. C#中hashtable的赋值、取值、遍历、排序操作

    一,哈希表(Hashtable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对,其 ...

  4. 读取文件内容返回List<String>类型

    文件内容格式: string1 string2 String 3 …… 很简单,两句话 String content = new String(Files.readAllBytes(Paths.get ...

  5. MVC中不能使用原生态的#include ,可替代的解决方案

    <!--#include file="../stuff/foo/box.aspx"--> 1.可以用 <%: Html.Partial("~/Views ...

  6. javascript判断浏览器

    function getExplorer() { //IE if (navigator.userAgent.indexOf("MSIE")>=0) { } //Firefox ...

  7. 武汉科技大学ACM:1008: 零起点学算法64——回型矩阵

    Problem Description 输出n*m的回型矩阵 Input 多组测试数据 每组输入2个整数 n和m(不大于20) Output 输出n*m的回型矩阵,要求左上角元素是1,(每个元素占2个 ...

  8. 托盘图标、气泡以及任务栏崩溃后的自动添加——Shell_NotifyIcon

    托盘图标使用函数 Shell_NotifyIcon 创建.修改和删除,参数主要使用 NOTIFYICONDATA 结构. 任务栏启动时会给所有顶层窗口发送 TaskbarCreated 消息,由于不同 ...

  9. 网易JS面试题与Javascript词法作用域说明

    调用对象位于作用域链的前端,局部变量(在函数内部用var声明的变量).函数参数及Arguments对象都在函数内的作用域中--这意味着它们隐藏了作用域链更上层的任何同名的属性. 2010年9月14日, ...

  10. Oracle数据库之PL/SQL异常处理

    Oracle数据库之PL/SQL异常处理 异常指的是在程序运行过程中发生的异常事件,通常是由硬件问题或者程序设计问题所导致的. PL/SQL程序设计过程中,即使是写得最好的程序也可能会遇到错误或未预料 ...