hdu4111 Alice and Bob

67 篇文章 1 订阅

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值