1253.Problem A. Alice and Bob
Description
Alice have a friend Bob, they like play games very much, They like to play games is to grab the stone, this classic game they play much times, so today they intend to make the classic reproduction, playing an overnight grab stone, they are two people who like innovation, so this time they got a new game is played
a. There are N heap stones here.
b. Each time you can select stones that do not exceed M heap for any operation
c. They play game in turns and cannot do nothing
d. People who cannot move stones are losers
e. Alice first
Input
The first line is T(0 < T <= 1000) T is TestCase
Next line is N, M(0 < N, M <= 10000)
Next line follow N number P, P is the number of stones in the stone heap(0 < P <= 10000)
Output
Case #TestCase: winner
If Alice win output Alice, otherwise Bob
Sample Input
15 11 2 3 4 5
Sample Output
Case #1: Alice
Source
Unknown
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int x[10005];
int maxx( int x, int y)
{
if( x > y )
return x;
else
return y;
}
int main()
{
int t;
scanf("%d", &t);
int cnt = 1;
while( t-- )
{
int ma = -1 , i;
memset( x, 0, sizeof( x ));
int n , m;
scanf("%d%d", &n, &m);
for( i = 0; i<n; i++)
{
int k = 0;
int temp;
scanf("%d", &temp);
while( temp )
{
x[k++] += temp%2;///就是temp&2
temp = temp/2;
}
ma = maxx ( ma, k-1);
}
int flag = 0;
for( i = 0; i<=ma; i++)
{
if( x[i]%( m+1) != 0)
{
flag = 1;
printf("Case #%d: Alice\n", cnt++);
break;
}
}
if( flag == 0)
{
printf("Case #%d: Bob\n", cnt++);
}
}
}