HDU, hduacm
Problem DescriptionHere is a game for two players. The rule of the game is described below:
● In the beginning of the game, there are a lot of piles of beads.
● Players take turns to play. each turn, player choose a pile I and remove some (at least one) beads from it. then he coshould do nothing or split pile I into two piles with a beads and B beads. (a, B> 0 and a + B equals to the number of beads of pile I after removing)
● If after a player's turn, there is no beads left, the player is the winner.
Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game.
InputThere are multiple test cases. Please process till EOF.
For each test case, the first line contains a postive integer n (n <105) means there are n piles of beads. the next line contains n postive integer, the I-th postive integer ai (ai <231) means there are ai beads in the I-th pile.
OutputFor each test case, if the first player can win the game, ouput "Win" and if he can't, ouput "Lose"
Sample Input
1121 131 2 3
Sample Output
WinLoseLose: after taking the rock, you can divide the heap into two ideas: similar to Nim games: an exception or a rise of 0, the first hand to lose#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>typedef __int64 ll;using namespace std;int main() {int n;while (scanf("%d", &n) != EOF) {ll ans = 0;ll tmp;for (int i = 0; i < n; i++) {scanf("%I64d", &tmp);ans ^= tmp;}if (ans == 0)printf("Lose\n");else printf("Win\n");} }
Hdu acm 1052.
Try:
4
1 2 4 5
2 3 3 4
0
The slow speed is caused by sorting and qsort is attempted.
------------------------------
For more information about qsort, see:
Www.cppreference.com/wiki/c/other/qsort
------------------------------
2
2 3
1 3
0
Add more points to the question.
Hdu 1004 Runtime Error (ACCESS_VIOLATION)
There are a lot of problems... the following code can ac
STACK_OVERFLOW refers to stack space overflow. google is recommended for Stack. It is shown that a is too large to open a large array.
ACCESS_VIOLATION is generally because the array is out of bounds. Here, you are shown as B is too small. When n> 100, the subscript I and j will be out of bounds.
# Include <stdio. h>
# Include <string. h>
Char a [1001] [20]; // 500 is changed to WA, and STACK_OVERFLOW is changed to WA.
Int main ()
{
Int B [1001], I, maxi, max, j, n;
While (scanf ("% d", & n )! = EOF)
{
If (n = 0) break; // The end condition given by the question stem. Do not ignore this condition.
For (I = 0; I <n; I ++)
Scanf ("% s", a [I]);
For (I = 0; I <n; I ++)
{
B [I] = 0;
For (j = I + 1; j <n; j ++)
If (strcmp (a [j], a [I]) = 0)
B [I] ++;
}
Max = B [0];
For (I = 0; I <n; I ++)
If (B [I]> = max)
{Max = B [I];
Maxi = I;
}
Printf ("% s \ n", a [maxi]);
}
Return 0;
}