题解: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 a a of size n n n.

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

In one operation, a player can do:

  • Choose an index i i i ( 1 ≤ i ≤ n 1 \le i \le n 1in) such that a i ≥ m x a_{i} \geq mx aimx and set m x mx mx to a i a_{i} ai. Then, set a i a_{i} ai to 0 0 0.

Determine whether Alice has a winning strategy.

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

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

在一次操作中,玩家可以

  • 选择 i i i 1 ≤ i ≤ n 1 \le i \le n 1in )这样的索引 a i ≥ m x a_{i} \geq mx aimx ,并将 m x mx mx 设置为 a i a_{i} ai 。然后将 a i a_{i} ai 设为 0 0 0

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

Input

The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103) — the number of test cases.

For each test case:

  • The first line contains an integer n n n ( 2 ≤ n ≤ 50 2 \leq n \leq 50 2n50) — the size of the array.
  • The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ n 1 \leq a_i \leq n 1ain) — the elements of the array.

输入

第一行包含一个整数 t t t 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103 )。( 1 ≤ t ≤ 1 0 3 1 \leq t \leq 10^3 1t103 ) - 测试用例的数量。

对于每个测试用例

  • 第一行包含一个整数 n n n ( 2 ≤ n ≤ 50 2 \leq n \leq 50 2n50 ) - 数组的大小。
  • 第二行包含 n n n 个整数 a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,,an ( 1 ≤ a i ≤ n 1 \leq a_i \leq n 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 i=1 i=1 since a 1 = 2 ≥ m x = 0 a_1=2 \ge mx=0 a1=2mx=0.

After Alice’s operation, a = [ 0 , 1 ] a=[0,1] a=[0,1] and m x = 2 mx=2 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 i=1 i=1, after Alice’s operation: a = [ 0 , 1 ] a=[0,1] a=[0,1] and m x = 1 mx=1 mx=1. Then, Bob can choose i = 2 i=2 i=2 since a 2 = 1 ≥ m x = 1 a_2=1 \ge mx=1 a2=1mx=1. After Bob’s operation: a = [ 0 , 0 ] a=[0,0] a=[0,0] and m x = 1 mx=1 mx=1. Alice can not do any operation. Bob wins.

在第一个测试案例中,爱丽丝可以选择 i = 1 i=1 i=1 ,因为 a 1 = 2 ≥ m x = 0 a_1=2 \ge mx=0 a1=2mx=0

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

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

例如,如果爱丽丝选择 i = 1 i=1 i=1 ,那么在爱丽丝的操作之后, a = [ 0 , 1 ] a=[0,1] a=[0,1] m x = 1 mx=1 mx=1 a = [ 0 , 1 ] a=[0,1] a=[0,1] m x = 1 mx=1 mx=1 。那么,鲍勃可以选择 i = 2 i=2 i=2 ,因为 a 2 = 1 ≥ m x = 1 a_2=1 \ge mx=1 a2=1mx=1 。鲍勃操作后 a = [ 0 , 0 ] a=[0,0] a=[0,0] m x = 1 mx=1 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;
}

搬运自https://www.cnblogs.com/jiejiejiang2004/p/18314425
博主已同意,我就是博主

  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值