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.
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.
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 ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
5711693 | 2012-04-05 19:36:24 | Accepted | 4023 | 0MS | 252K | 2810 B | C++ | ahfywff |
5711417 | 2012-04-05 19:15:46 | Wrong Answer | 4023 | 15MS | 252K | 2800 B | C++ | 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;
}