John
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 5707 Accepted Submission(s): 3310
Problem Description
Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so on. Please note that each player has to eat at least one M&M during his turn. If John (or his brother) will eat the last M&M from the box he will be considered as a looser and he will have to buy a new candy box.
Both of players are using optimal game strategy. John starts first always. You will be given information about M&Ms and your task is to determine a winner of such a beautiful game.
Both of players are using optimal game strategy. John starts first always. You will be given information about M&Ms and your task is to determine a winner of such a beautiful game.
Input
The first line of input will contain a single integer T – the number of test cases. Next T pairs of lines will describe tests in a following format. The first line of each test will contain an integer N – the amount of different M&M colors in a box. Next line will contain N integers Ai, separated by spaces – amount of M&Ms of i-th color.
Constraints:
1 <= T <= 474,
1 <= N <= 47,
1 <= Ai <= 4747
Constraints:
1 <= T <= 474,
1 <= N <= 47,
1 <= Ai <= 4747
Output
Output T lines each of them containing information about game winner. Print “John” if John will win the game or “Brother” in other case.
Sample Input
2 3 3 5 1 1 1
Sample Output
John
Brother
#include<iostream>
#include<string.h>
using namespace std;
int main(int argc, char const *argv[]) {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
int temp = 0, sum = 0;
for (int i = 1; i <= n; i ++) {
int x;
scanf("%d", &x);
if (x >= 2)
sum ++;
temp ^= x;
}
if (sum >= 2) {
if (temp)
printf("John\n");
else
printf("Brother\n");
}
else if (sum == 1)
printf("John\n");
else {
if (temp)
printf("Brother\n");
else
printf("John\n");
}
}
return 0;
}
Digital Deletions
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3277 Accepted Submission(s): 1179
Problem Description
Digital deletions is a two-player game. The rule of the game is as following.
Begin by writing down a string of digits (numbers) that's as long or as short as you like. The digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and appear in any combinations that you like. You don't have to use them all. Here is an example:
On a turn a player may either:
Change any one of the digits to a value less than the number that it is. (No negative numbers are allowed.) For example, you could change a 5 into a 4, 3, 2, 1, or 0.
Erase a zero and all the digits to the right of it.
The player who removes the last digit wins.
The game that begins with the string of numbers above could proceed like this:
Now, given a initial string, try to determine can the first player win if the two players play optimally both.
Begin by writing down a string of digits (numbers) that's as long or as short as you like. The digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and appear in any combinations that you like. You don't have to use them all. Here is an example:
On a turn a player may either:
Change any one of the digits to a value less than the number that it is. (No negative numbers are allowed.) For example, you could change a 5 into a 4, 3, 2, 1, or 0.
Erase a zero and all the digits to the right of it.
The player who removes the last digit wins.
The game that begins with the string of numbers above could proceed like this:
Now, given a initial string, try to determine can the first player win if the two players play optimally both.
Input
The input consists of several test cases. For each case, there is a string in one line.
The length of string will be in the range of [1,6]. The string contains only digit characters.
Proceed to the end of file.
The length of string will be in the range of [1,6]. The string contains only digit characters.
Proceed to the end of file.
Output
Output Yes in a line if the first player can win the game, otherwise output No.
Sample Input
0 00 1 20
Sample Output
Yes Yes No
No
蜜汁超时,蜜汁超内存
#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = 1e6 + 5;
int SG[N];
void GetSG(int n) {
int len = log10(n) + 1;
int t = n ;
int mult = 1;
while(t) {
int m = t % 10;
t /= 10;
int t1 = n;
for (int j = m + 1; j <= 9; j ++) {
t1 += mult;
SG[t1] = 1;
}
mult *= 10;
}
t = n;
int k = 1;
while (len < 6) {
t *= 10;
for (int i = 0; i < k; i ++) {
SG[t + i] = 1;
}
k *= 10;
len ++;
}
}
int main()
{
char s[10];
memset(SG, 0, sizeof(SG));
SG[0] = 1;
for (int i = 1; i < 1000000; i ++) {
if (!SG[i]) GetSG(i);
}
while (gets(s)) {
if (s[0] == '0') {
cout << "Yes" <<endl;
continue;
}
int t = atoi(s);
if (SG[t])
cout << "Yes" <<endl;
else
cout << "No" <<endl;
}
return 0;
}