XTU 1209 Alice and Bob (game)

Source: Internet
Author: User
Tags time limit

Alice and Bob
accepted:174 submit:342
Time limit:1000 MS Memory limit:65536 KB

problem Description

The famous "Alice and Bob" are playing a game again. So is comes the new problem which need a person smart as you to decide the winner. The problem is as Follows:they be playing on a rectangle paper, Alice and Bob take turn alternatively, for each turn, a P Eople cut the rectangle vertically or horizontally, the result of both rectangle after cut must be identical, also the side MU St is integer, after the cut, one rectangle'll be descarded. The first people fail to cut lose the game. Of course, Alice makes first as usual. Input

First line contains an integer t indicate there is t cases (1≤t≤1000) for each case:the input consists of the integers w an D h (1≤w,h≤1,000,000,000), the size of rectangle. Output

First output case numberfor each case output Alice or BOB, indicate the winner. Sample Input

2
1 2)
2 2

Sample Output
Case 1:alice Case
2:bob


SourceXTU Onlinejudge




Analytical:

Simple game. Because it is evenly divided, you only need to determine the number of W and H containing factor 2.




AC Code:

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

int main () {
    int t;
    LL W, H;
    scanf ("%d", &t);
    for (int i=1; i<=t; i++) {
        scanf ("%lld%lld", &w, &h);
        int ans = 0;
        while (w% 2 = = 0) {ans + +; w/= 2;}
        while (h% 2 = = 0) {ans + +; h/= 2;}
        printf ("Case%d:%s\n", I, ans% 2?) "Alice": "Bob");
    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.