Alice's Game - HDU 3544 博弈
来源:互联网 发布:淘宝网皇冠店铺转让 编辑:程序博客网 时间:2024/06/06 08:25
Alice's Game
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 511 Accepted Submission(s): 211
Problem Description
Alice and Bob have got a lot of chocolates. All the chocolates are rectangles of different shapes as Xi * Yi.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 Xi * Yi, can only split into A * Yi, and B * Yi where A + B = Xi and A, B > 0. And for Bob, a chocolate Xi * Yi, can only split into Xi * A, and Xi * B where A + B = Yi 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 Xi * Yi, can only split into A * Yi, and B * Yi where A + B = Xi and A, B > 0. And for Bob, a chocolate Xi * Yi, can only split into Xi * A, and Xi * B where A + B = Yi 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 Xi and Yi, denoting the chocolate sized Xi * Yi. (1 <= Xi, Yi <= 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 Xi and Yi, denoting the chocolate sized Xi * Yi. (1 <= Xi, Yi <= 1000000000)
Output
For each test cases, output "Alice" when Alice will win, and "Bob" otherwise. See sample test cases for further details.
Sample Input
411 112 122 22 113 2
Sample Output
Case 1: BobCase 2: AliceCase 3: AliceCase 4: Bob
思路:同样不理解题目,本来想的是每次从中间分,但是怕超时,后来去网上看别人的思路,发现写的都是每次取另一个人切完的小的那块继续分。问题是题目中只说把一块切成两块,并没有说要丢掉一块啊。。。。那这样的话题意只能理解成第二个人可以选择新切成的两块中的一块并吃掉另一块。。。
AC代码如下:
#include<cstdio>#include<cstring>using namespace std;typedef long long ll;int T,t,n,m;int main(){ int i,j,k; ll x,y,a,b; scanf("%d",&T); for(t=1;t<=T;t++) { scanf("%d",&n); a=b=0; for(i=1;i<=n;i++) { scanf("%I64d%I64d",&x,&y); while(x>1 && y>1) { x/=2;y/=2; } if(y==1) a+=x-1; if(x==1) b+=y-1; } printf("Case %d: ",t); if(a>b) printf("Alice\n"); else printf("Bob\n"); }}
0 0
- hdu 3544 Alice's Game 【博弈】
- Alice's Game - HDU 3544 博弈
- HDU 3544 Alice's Game (不平等博弈)*
- HDU 3544 Alice's Game(贪心博弈)
- HDOJ 3544 Alice's Game 博弈
- HDU 3544 Alice's Game
- HDU 3544 Alice's Game
- Alice‘s Game (hdu 3544)
- hdu 3544 Alice's Game
- hdu3544 Alice's Game----博弈 贪心
- hdu3544 Alice's Game
- [HDU3544] Alice's Game
- HDU 1525 Euclid's Game (博弈)
- hdu 2147 kiki's game(基础博弈)
- HDU 2147 kiki's game 博弈
- hdu-2147:kiki's game 博弈
- hdu 2147 kiki's game 简单博弈
- hdu 1525 Euclid's Game 博弈
- ant 编译 错误: 编码UTF8的不可映射字符
- fgets()函数和sscanf()函数的用法
- 【C语言】编写函数实现库函数atoi,把字符串转换成整形(考虑数字过大)
- oracle 中用pl/sql编辑记录里面的值 for update
- ArrayList和LinkedList的区别
- Alice's Game - HDU 3544 博弈
- linux中mkdir创建目录命令使用说明
- jsoncpp的读写操作
- 【C语言】编写函数实现库函数atof
- Git 命令参考中文整理
- Python浅析之类的写法
- 图解告诉你怎么在VS2010下调试DLL
- jdk install, Ubuntu
- C#+Oracle:ATM自助取款机开发