NC231739. Odd Stones
描述
“Look at those stones!”
“So odd they are!”
Whispers aroused in the crowd.
As we all know, if a stone looks very odd, we call it an odd stone. A legendary odd stone could be sold more expensive than gold in the same weight.
This is an auction house in the year of 2022. They would not wonder that odd stones will become so cheap in up to 998242331 years.
There’ s a game call “Odd Stone” will be popular in the year of 998244353 due to the low prize of odd stones.
The rule of this game is:
Two players get a heap of odd stones, then divide them into several piles or just leave it as the original heap, and take exactly odd number of odd stone(s) away from one pile you can randomly choose from those piles in turns. Once all the odd stones were taken away and it is your turn, you will lose this game, and vice versa.
Cindy furtively told you: “This game has an optimal strategy. Once you deploy this optimal strategy. you may win this game, but if you deploy this strategy and you lose, you can’ t win this game with any other strategy while your opponent deploy this optimal strategy.”.
Alice and Bob were both told by Cindy, and Cindy also told them details about the optimal strategy, but did’ t tell you since Cindy thought you are so intelligent to know that .
One day, Alice and Bob are playing this “Odd Stone” game, they will play t times, and at each time, there are ()(n may be different at different times) pile(s) of stone(s), and the -th pile of stone has exactly () stone(s). Alice is the first player to take away odd stone(s). Each time, they both deploy the optimal strategy.
Denny is watching aside, he wants to know who will win this game while Alice and Bob both deploy the optimal strategy, so he asks you for answer, could you tell him who is the winner?
输入描述
The first line contains exactly one integer — the number of times Alice and Bob play this game, in other words, the number of testcases.
The first line of each testcases contains exactly one integer — the number of odd stone piles.
The second line of each testcases contains integers, the -th integer is — the number of odd stone(s) of the -th pile of odd stone(s)
It is guarantee that , .
输出描述
For each case, just print the winner's name, "Alice" or "Bob" without quotes, in one line per case.
示例1
输入:
2 3 1 3 5 4 1 3 5 7
输出:
Alice Bob
示例2
输入:
1 4 999999999 999999999 999999999 999999999
输出:
Bob
C++ 解法, 执行用时: 24ms, 内存消耗: 560K, 提交时间: 2022-01-02 12:41:02
#include<iostream> using namespace std; signed main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); int x,ans=0; while(n--){ scanf("%d",&x); ans^=x; } printf(ans&1?"Alice\n":"Bob\n"); } return EOF+1; }
pypy3 解法, 执行用时: 347ms, 内存消耗: 34772K, 提交时间: 2022-01-02 15:52:08
T = int(input()) for i in range(T): n = int(input()) a = list(map(int, input().split())) a_sum = sum(a) if a_sum & 1: print("Alice") else: print('Bob')
Python3 解法, 执行用时: 164ms, 内存消耗: 14252K, 提交时间: 2022-01-02 13:55:50
for _ in range(int(input())): input() print('Alice'if len([i for i in map(int,input().split())if i&1])&1else'Bob')