题解: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
They take turns to do operations, with Alice starting first. The player who can not operate will lose. At first, a variable
In one operation, a player can do:
- Choose an index
( ) such that and set to . Then, set to .
Determine whether Alice has a winning strategy.
爱丽丝和鲍勃在大小为
他们轮流进行操作,爱丽丝先开始。不会运算的一方将输掉比赛。一开始,变量
在一次操作中,玩家可以
- 选择
( )这样的索引 ,并将 设置为 。然后将 设为 。
判断爱丽丝是否有一个获胜的策略。
Input
The first line contains an integer
For each test case:
- The first line contains an integer
( ) — the size of the array. - The second line contains
integers ( ) — the elements of the array.
输入
第一行包含一个整数
对于每个测试用例
- 第一行包含一个整数
( ) - 数组的大小。 - 第二行包含
个整数 ( ) - 数组元素。
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
After Alice's operation,
In the second test case, Alice doesn't have a winning strategy.
For example, if Alice chooses
注
在第一个测试案例中,爱丽丝可以选择
爱丽丝操作后,
在第二个测试案例中,爱丽丝没有获胜策略。
例如,如果爱丽丝选择
题解
从大到小去判断出现过的数字的次数,
只要有一个数字出现过的次数为奇数,
那就是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 2024-07-21 10:42 Jiejiejiang 阅读(118) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」