jiejiejiang2004

题解:Codeforces Round 960 (Div. 2) A

A. Submission Bait

time limit per test: 1 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

Alice and Bob are playing a game in an array a of size n.

They take turns to do operations, with Alice starting first. The player who can not operate will lose. At first, a variable mx is set to 0.

In one operation, a player can do:

  • Choose an index i (1in) such that aimx and set mx to ai. Then, set ai to 0.

Determine whether Alice has a winning strategy.

爱丽丝和鲍勃在大小为 n 的数组 a 中进行游戏。

他们轮流进行操作,爱丽丝先开始。不会运算的一方将输掉比赛。一开始,变量 mx 被设置为 0

在一次操作中,玩家可以

  • 选择 i1in )这样的索引 aimx ,并将 mx 设置为 ai 。然后将 ai 设为 0

判断爱丽丝是否有一个获胜的策略。

Input

The first line contains an integer t (1t103) — the number of test cases.

For each test case:

  • The first line contains an integer n (2n50) — the size of the array.
  • The second line contains n integers a1,a2,,an (1ain) — the elements of the array.

输入

第一行包含一个整数 t1t103 )。( 1t103 ) - 测试用例的数量。

对于每个测试用例

  • 第一行包含一个整数 n ( 2n50 ) - 数组的大小。
  • 第二行包含 n 个整数 a1,a2,,an ( 1ain ) - 数组元素。

Output

For each test case, if Alice has a winning strategy, output "YES". Otherwise, output "NO".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

输出

对于每个测试用例,如果 Alice 的策略获胜,则输出 "YES"。否则,输出 "否"。

可以用任何大小写(大写或小写)输出答案。例如,字符串 "yEs"、"yes"、"Yes "和 "YES "将被识别为肯定回答。

Example

input

5
2
2 1
2
1 1
3
3 3 3
4
3 3 4 4
4
1 2 2 2

output

YES
NO
YES
NO
YES

Note

In the first test case, Alice can choose i=1 since a1=2mx=0.

After Alice's operation, a=[0,1] and mx=2. Bob can not do any operation. Alice wins.

In the second test case, Alice doesn't have a winning strategy.

For example, if Alice chooses i=1, after Alice's operation: a=[0,1] and mx=1. Then, Bob can choose i=2 since a2=1mx=1. After Bob's operation: a=[0,0] and mx=1. Alice can not do any operation. Bob wins.

在第一个测试案例中,爱丽丝可以选择 i=1 ,因为 a1=2mx=0

爱丽丝操作后, a=[0,1]mx=2 。鲍勃无法进行任何操作。爱丽丝获胜。

在第二个测试案例中,爱丽丝没有获胜策略。

例如,如果爱丽丝选择 i=1 ,那么在爱丽丝的操作之后, a=[0,1]mx=1a=[0,1]mx=1 。那么,鲍勃可以选择 i=2 ,因为 a2=1mx=1 。鲍勃操作后 a=[0,0]mx=1 。爱丽丝无法进行任何操作。鲍勃获胜。

题解
从大到小去判断出现过的数字的次数,
只要有一个数字出现过的次数为奇数,
那就是YES;
否则就是NO。

代码

#include <bits/stdc++.h>
#define int long long
const int N = 1e7 + 10;
int t;
int a[N];
void solve() {
int n;
std::cin >> n;
for(int i = 0 ; i < n ; i ++) {
std::cin >> a[i];
}
std::sort(a,a+n,std::greater<int>());
int jud = 0;
int * st = a, * en = a+n;
while(!jud && st != en) {
int num = std::count(st,en,*st);
if(num & 1) jud = 1;
else st += num;
}
std::cout << (jud ? "YES\n" : "NO\n");
return ;
}
signed main() {
std::cin >> t;
while(t--) {
solve();
}
return 0;
}

posted on   Jiejiejiang  阅读(118)  评论(0编辑  收藏  举报

编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」

导航

统计信息

点击右上角即可分享
微信分享提示