Alice's Game
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 232 Accepted Submission(s): 95
Problem Description
Alice and Bob have got a lot of chocolates. All the chocolates are rectangles of different shapes as X
i * Y
i.They decide to play an interesting game on the chocolates. They take turns choose a chocolate and split it into two pieces. The one who can not take operations lose. Due to the game is too simple, the additional rules apply. Alice is only allowed to split the chocolate vertically, and Bob is only allowed to split the chocolate horizontally.
Specifically, for Alice, a chocolate X i * Y i, can only split into A * Y i, and B * Y i where A + B = X i and A, B > 0. And for Bob, a chocolate X i * Y i, can only split into X i * A, and X i * B where A + B = Y i and A, B > 0.
Alice and Bob are clever enough to take the optimal operation, if Alice plays first, your are to decide who will win.
Specifically, for Alice, a chocolate X i * Y i, can only split into A * Y i, and B * Y i where A + B = X i and A, B > 0. And for Bob, a chocolate X i * Y i, can only split into X i * A, and X i * B where A + B = Y i and A, B > 0.
Alice and Bob are clever enough to take the optimal operation, if Alice plays first, your are to decide who will win.
Input
The input contains multiple test cases. The first line of input contains a single integer denoting the number of test cases.
For each test case, the first line contains an integer N, the number of pieces of chocolates. (1 <= N <= 100)
For the next N lines, each line contains two integers X i and Y i, denoting the chocolate sized X i * Y i. (1 <= X i, Y i <= 1000000000)
For each test case, the first line contains an integer N, the number of pieces of chocolates. (1 <= N <= 100)
For the next N lines, each line contains two integers X i and Y i, denoting the chocolate sized X i * Y i. (1 <= X i, Y i <= 1000000000)
Output
For each test cases, output "Alice" when Alice will win, and "Bob" otherwise. See sample test cases for further details.
Sample Input
4 1 1 1 1 2 1 2 2 2 2 1 1 3 2
Sample Output
Case 1: Bob Case 2: Alice Case 3: Alice Case 4: Bob
Author
HyperHexagon
Source
Recommend
zhengfeng
题意:给一块n*m的巧克力,Alice只能垂直切,切成A*m和B*m,并且A+B=n,Bob只能横切,只能切成A*n和B*n,并且A+B=m。
对于n*n的这种巧克力,谁先切了第一刀,就直接让对方有切两刀的机会,所以Alice不可能去切这种巧克力,可以直接无视这种。
后一人会尽量选前一人切后小的一块切。
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#define ll __int64
using namespace std;
int main()
{
int t,n;
int count=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ll x,y;
ll c1=0,c2=0;
for(int i=1;i<=n;i++)
{
scanf("%I64d%I64d",&x,&y);
while(x>1&&y>1)
{
x>>=1;y>>=1;
c1++;c2++;
}
if(x==1) c2+=y-1;
else c1+=x-1;
}
printf("Case %d: ",count++);
if(c1>c2) puts("Alice");
else puts("Bob");
}
}