P2197 【Template】Nim Game

Description

Two players, A and B, are playing the Nim game. The rules of the Nim game are as follows: There are $n$ piles of stones on the ground (each pile has fewer than $10^4$ stones). On each turn, a player may remove any positive number of stones from exactly one pile; it is allowed to take all stones from that pile, but taking none is not allowed. The player who cannot make a move (i.e., when no stones remain) loses. Given that A moves first and the sizes of the $n$ piles are known, determine whether there exists a winning strategy for the first player.

Input Format

This problem has multiple testdata. The first line contains an integer $T$ ($T \le 10$), indicating there are $T$ sets of testdata. Next, each set of testdata consists of two lines. The first line contains an integer $n$, the number of piles, with $n \le 10^4$. The second line contains $n$ integers, representing the number of stones in each pile.

Output Format

Output $T$ lines. For each set of testdata, output `Yes` if there exists a winning strategy for the first player; otherwise, output `No`.

Explanation/Hint

Translated by ChatGPT 5