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\) (\(1 \le i \le n\)) such that \(a_{i} \geq mx\) and set \(mx\) to \(a_{i}\). Then, set \(a_{i}\) to \(0\).

Determine whether Alice has a winning strategy.

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

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

在一次操作中,玩家可以

  • 选择 \(i\)\(1 \le i \le n\) )这样的索引 \(a_{i} \geq mx\) ,并将 \(mx\) 设置为 \(a_{i}\) 。然后将 \(a_{i}\) 设为 \(0\)

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

Input

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

For each test case:

  • The first line contains an integer \(n\) (\(2 \leq n \leq 50\)) — the size of the array.
  • The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(1 \leq a_i \leq n\)) — the elements of the array.

输入

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

对于每个测试用例

  • 第一行包含一个整数 \(n\) ( \(2 \leq n \leq 50\) ) - 数组的大小。
  • 第二行包含 \(n\) 个整数 \(a_1, a_2, \ldots, a_n\) ( \(1 \leq a_i \leq n\) ) - 数组元素。

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 \(a_1=2 \ge mx=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 \(a_2=1 \ge mx=1\). After Bob's operation: \(a=[0,0]\) and \(mx=1\). Alice can not do any operation. Bob wins.

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

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

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

例如,如果爱丽丝选择 \(i=1\) ,那么在爱丽丝的操作之后, \(a=[0,1]\)\(mx=1\)\(a=[0,1]\)\(mx=1\) 。那么,鲍勃可以选择 \(i=2\) ,因为 \(a_2=1 \ge mx=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 2024-07-21 10:42  Jiejiejiang  阅读(59)  评论(0编辑  收藏  举报

导航