hdu4111 Alice and Bob
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
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!
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.
3
1 1 2
2
3 4
3
2 3 5
Case #2: Bob
Case #3: Bob
#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的更多相关文章
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- sdutoj 2608 Alice and Bob
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...
- hdu 4268 Alice and Bob
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 2014 Super Training #6 A Alice and Bob --SG函数
原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- 位运算 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 ...
- SDUT 2608:Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
随机推荐
- Mounting File Systems
1.Mounting File Systems Just creating a partition and putting a file system on it is not enough to s ...
- 一个好用的Python备份mysql的脚本
前几天打算用Python写一个mysql脚本,上Google看了下老外写的,写的挺好的,原地址在http://tecadmin.net/python-script-for-mysql-database ...
- C# 窗口传值的方法
方法一: A to B 设置FormB 为 带参数的构造函数 public Form2( object msg) { InitializeComponent(); } 方法二: A to B 定义一 ...
- libthrift0.9.0解析(二)之TSimpleServer
TSimpleServer简单实现Tserver,代码如下. /** * Simple singlethreaded server for testing. * */ public class TSi ...
- JavaScript 客户端JavaScript之 脚本化文档
客户端JavaScript的存在把静态HTML转变为交互式的Web应用程序,脚本化Web页面的内容正是JavaScript存在的理由. 一个文档对象模型或者说DOM就是一个API,它定义了如何访问 ...
- 武汉科技大学ACM:1003: 看美女
Problem Description “排排站,赏美女……” YJ师兄在今年牡丹江赛区人品爆发,怒摘银奖,心情倍好,现组织大家去黄家湖边站成一排看美女 ^.^ N个人站成一排.不巧,美女们只在队伍的 ...
- 2.2 文件 I/O 的基石:Path
Path通常代表文件系统中的位置,能浏览任何类型的文件系统,包括zip归档文件系统: 文件系统中的几个概念:目录树.根目录.绝对路径.相对路径: NIO.2中的Path是一个抽象构造,你所创建和处理的 ...
- 零基础创建RCP工程
一.环境搭建 1. 安装java jdk,我选择的是jdk 1.7版本,配置环境变量: 2. 下载并安装java EE: 二.创建工程 1. 打开File-> New ->other -& ...
- 《python基础教程》笔记之 列表
list函数 list函数将其他类型的序列转换为列表,如 >>> list("hello world")['h', 'e', 'l', 'l', 'o', ' ' ...
- DOS头 IMAGE_DOS_HEADER
IMAGE_DOS_HEADER STRUCT { +0h WORD e_magic // Magic DOS signature MZ(4Dh 5Ah) DOS可执行文件标记 +2h WORD e_ ...