HDU 4023 Game (博弈)

1 篇文章 0 订阅
Problem Description
Alice and Bob are playing game with each other. They play the game on a 2D board. Alice has many vertical 1*2 tiles while Bob has many horizontal 2*1 tiles. They take turn to place their own tiles on the board. Considering about that the tiles cannot overlap each other, the player cannot do the placement any more loses. Since this is such a complex game that they could not find optimal method to play that, Alice decide to simplify this game by replace the large 2D board by some small ones. Alice set up a lot of Tetris tiles instead of the original 2D board. In the other words, the player can only place their own vertical or horizontal tiles on the Tetris-like board. Each player can choose one possible place on any Tetris tiles to place its own tiles. In fact, there are following 15 types of Tetris playground.

The playground cannot be transformed in any ways, including reflection and rotation.
Given the number of each type of tiles, you are asked to determine who will win the game if Alice plays first and both players are playing optimal.
 

Input
There are multiple test cases; the first line of input contains a single integer denoting the number of test cases.
For each test case, there are only one line contains 15 integers denoting the number of Tetris tiles of the above 15 types. All the numbers are no greater than 100.
 

Output
For each test cases, output “Alice” if Alice will win the game and both player plays optimally, “Bob” otherwise.
 

Sample Input
  
  
3 5 4 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 100 100 0 0 0 0 0 0 0 0 0 2 1 0 0
 

Sample Output
  
  
Case #1: Alice Case #2: Bob Case #3: Alice
 

Source
 

分析:

Alice的选择由先到后依次为:(15)->(5),(6)->(3),(4)->(11),(12),(13),(14)->(7),(8),(9),(10)->(1);

Bob的选择由先到后依次为:(15)->(3),(4)->(5),(6)->(11),(12),(13),(14)->(7),(8),(9),(10)->(2).

然后,模拟一遍即可。


Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor
57116932012-04-05 19:36:24Accepted40230MS252K2810 BC++ahfywff
57114172012-04-05 19:15:46Wrong Answer402315MS252K2800 BC++ahfywff

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    int t, a[20];
    scanf("%d", &t);
    for (int cas = 1; cas <= t; ++cas)
    {
        // ta: 仅Alice能放的位置数 
        // tb: 仅Bob能放的位置数 
        // next: 游戏先手,0表示Alice,1表示Bob 
        int ta = 0, tb = 0, next = 0;
        for (int i = 1; i <= 15; ++i)
            scanf("%d", &a[i]);
        ta += a[1] * 2;
        tb += a[2] * 2;
        if (a[15] & 1)
        {
            ta++; next = 1;
        }
        
        if (a[3] + a[4] > a[5] + a[6])
        {
            int res = (a[3] + a[4]) - (a[5] + a[6]);
            if (res & 1)
            {
                if (next == 0)
                {
                    tb += (res - 1) / 2;
                    next = 1;
                }
                else
                {
                    tb += (res + 1) / 2;
                    next = 0;
                }
            }
            else tb += res / 2;
        }
        else if (a[3] + a[4] < a[5] + a[6])
        {
            int res = (a[5] + a[6]) - (a[3] + a[4]);
            if (res & 1)
            {
                if (next == 0)
                {
                    ta += (res + 1) / 2;
                    next = 1;
                }
                else
                {
                    ta += (res - 1) / 2;
                    next = 0;
                } 
            }
            else ta += res / 2;
        }
        
        if ((a[11]+a[12]+a[13]+a[14]) & 1)
        {
            next = !next;
        }
        
        if (a[7] + a[8] > a[9] + a[10])
        {
            int res = (a[7] + a[8]) - (a[9] + a[10]);
            if (res & 1)
            {
                if (next == 0)
                {
                    ta += (res - 1) / 2;
                    next = 1;
                }
                else
                {
                    ta += (res + 1) / 2;
                    next = 0;
                }
            }
            else ta += res / 2;
        }
        else if (a[7] + a[8] < a[9] + a[10])
        {
            int res = (a[9] + a[10]) - (a[7] + a[8]);
            if (res & 1)
            {
                if (next == 0)
                {
                    tb += (res + 1) / 2;
                    next = 1;
                }
                else
                {
                    tb += (res - 1) / 2;
                    next = 0;
                }
            }
            else tb += res / 2;
        }

        printf("Case #%d: ", cas);
        if (next == 0)
        {
            if (ta > tb) printf("Alice\n");
            else printf("Bob\n");
        }
        else
        {
            if (tb > ta) printf("Bob\n");
            else printf("Alice\n");
        }
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值