HDU 4023 Game (Game)

Source: Internet
Author: User
Game

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission (s): 638 Accepted Submission (s): 210

Problem DescriptionAlice and Bob are playing game with each other. they play the game on a 2D board. alice has implements vertical 1*2 tiles while Bob has implements 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 cocould 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 RIS-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.

 

InputThere 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 RIS tiles of the above 15 types. All the numbers are no greater than 100.

 

OutputFor each test cases, output "Alice" if Alice will win the game and both player plays optimally, "Bob" otherwise.

 

Sample Input3 5 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 0 0 0 0 0 0 0 2 1 0 0

 

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

 

SourceThe 36th ACM/ICPC Asia Regional Shanghai Site -- Online Contest

 

Recommendlcy

This question should be a classification question. Since it is a game, each step should strive for the greatest benefit for itself or bring the greatest loss to the other party, to put it first, you must consider your own interests and losses to the other party.

The final victory depends only on whether Alice can walk more steps than Bob, and this factor also depends on two points: 1. when neither party can bring losses to the other party, who is the first? 2. how many stable positions do the two sides have.

The so-called stable location means that no matter how the other party goes, they will not occupy the location they can go at any time.

From the above analysis perspective, we can divide the graph into the following five groups:

1. (1) (2) It is a group of stable positions of Alice and Bob, so we can put them to the end.

2. (15) as a group, in general, (15) Once a tile is put, it not only puts itself out of step, but also leaves a stable position for itself, at the same time, it can make the opponent lose two positions, so putting a tile in (15) is the most efficient way to go, so both sides will compete first (15 ).

3. (3) (4) (5) (6) is a group. As to why these four are a group, we may analyze the next one from Alice's perspective. If Alice goes (5) or (6), Alice can get a stable position at the same time, And let Bob lose a position. If Alice goes (3) (4 ), alice can make Bob lose two positions, so these two steps share the same benefits for Alice. In turn, it is the same for Bob. Since the two steps are the same, it is easy for us to make statistics. Let Alice go (5) (6), Bob go (3) (4) until one party finishes his home game, then divide the remaining (3) (4) or (5) (6 ).

4. (7) (8) (9) (10) is a group, because one party can hold down the other party, but the other party cannot hold down the other party. For details, see.

5. (11) (12) (13) (14) is a group. Why is this point not mentioned? It mainly means that after both parties finish the 3rd group, should we leave group 4th first or group 5th first.

First of all, from Alice's point of view, if going (7) (8), Bob can lose a position and go (11) (12) (13) (14) the same is true, but the two ways are different for Alice's benefits. If Alice goes (11 )~ (14) any one of them, and Bob will leave a stable location for Alice no matter (7) or (8), and if Alice goes (7) (8) bob (11 )~ (14) There is no such effect. So Alice will definitely leave (11 )~ (14), and then (7) (8 ). In the same way, Bob will definitely leave (11 )~ (14), and then (9) (10 ).

As for the score (7) (8) (9) (10), from Alice's perspective, taking (7) (8) will not only bring you out of this step, at the same time, it will make Bob lose a position, while Alice (9) (10) can only make her step by step, and it will not cause any loss to Bob, so Alice must first (7) (8), but for Bob, he will definitely leave (9) (10) first, and if (7) (8) or (9) (10) there is surplus, the two sides continue to divide points.

At last, add the (1) (2) statistics and check who should leave.

To sum up, in the statistical process, we need to record three quantities. who should go first when Alice and Bob have the remaining stable positions and take the graph of the current group, it doesn't matter if the graph is an even number, but if the graph is an odd number, the benefits of the previous hand will be different. At the same time, if the remaining stable positions of the two sides share the same part, we can skip these steps without statistics, because we only consider the difference in the number of locations where two people can walk, therefore, the same part will be offset, so it is not important.

 

# Include <stdio. h >#include <algorithm> # include <iostream> using namespace std; int a [16]; int main () {// freopen ("C. in "," r ", stdin); // freopen (" C. out "," w ", stdout); int T; int iCase = 0; int now; // records who is going now, 1 indicates Alice, 2 indicates Bob; int Alice, bob; // The retention steps of the two persons, scanf ("% d", & T); while (T --) {iCase ++; printf ("Case # % d: ", iCase); for (int I = 1; I <= 15; I ++) scanf (" % d ", & a [I]); alice = Bob = 0; now = 1; // Alice first if (a [15] % 2 = 0) // first grab 15th types of {Alice + = a [15]/2; // The same addition can be left blank, here it is easy to understand Bob + = a [15]/2;} else {Alice + = a [15]/2 + 1; Bob + = a [15]/2; now = 2; // Bob goes first} int tempa = a [5] + a [6]; // ALice grabs 5, 6 int tempb = a [3] + a [4]; // BOb grabs 3, 4 if (tempa = tempb) {Alice + = tempa; bob + = tempb;} else if (tempa <tempb) // Alice will grab {Alice + = tempa; Bob + = tempa; tempb-= tempa; if (tempb % 2 = 0) {Bob + = tempb/2;} else {if (now = 1) {now = 2; Bob + = tempb/2 ;} else {now = 1; Bob + = tempb/2 + 1 ;}} else {Alice + = tempb; Bob + = tempb; tempa-= tempb; if (tempa % 2 = 0) {Alice + = tempa/2;} else {if (now = 1) {now = 2; alice + = tempa/2 + 1;} else {now = 1; Alice + = tempa/2 ;}}} int temp = a [11] + a [12] + a [13] + a [14]; // The two robbed if (temp % 2 = 0) // evenly divided {Alice + = 0; Bob + = 0;} else {if (now = 1) {now = 2;} else {now = 1 ;}} tempa = a [7] + a [8]; tempb = a [9] + a [10]; if (tempa = tempb) {Alice + = 0; bob + = 0;} else if (tempa <tempb) // Alice will grab {Alice + = 0; Bob + = 0; tempb-= tempa; if (tempb % 2 = 0) {Bob + = tempb/2; // a} else {if (now = 1) {now = 2; bob + = tempb/2 + 1;} else {now = 1; Bob + = tempb/2; }}} else {tempa-= tempb; if (tempa % 2 = 0) {Alice + = tempa/2;} else {if (now = 1) {now = 2; Alice + = tempa/2 ;} else {now = 1; Alice + = tempa/2 + 1 ;}} Alice + = 2 * a [1]; Bob + = 2 * a [2]; if (now = 1) {if (Bob> = Alice) printf ("Bob \ n"); else printf ("Alice \ n ");} else {if (Alice> = Bob) printf ("Alice \ n"); else printf ("Bob \ n") ;}} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.