首页 > 其他分享 >题解:Codeforces Round 960 (Div. 2) A

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

时间:2024-07-21 10:52:09浏览次数:7  
标签:960 int 题解 Alice leq 爱丽丝 YES Div mx

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;
}

标签:960,int,题解,Alice,leq,爱丽丝,YES,Div,mx
From: https://www.cnblogs.com/jiejiejiang2004/p/18314243

相关文章

  • Codeforces Round 960 (Div. 2) 补题记录(A~D)
    打的稀烂,但是还是上分了(A考虑对值域做一个后缀和。若某一个后缀和的值是奇数那么先手就可以获胜。否则就不可以获胜。(我才不会告诉你我这题吃了一次罚时的)#pragmaGCCoptimize(3)#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;intmysqrt(intx){......
  • 使用牛顿法近似整数的 sqrt,ZeroDivisionError
    Sqrt(x)给定一个非负整数x,返回x的平方根,向下舍入到最接近的整数。返回的整数也应该是非负数。不得使用任何内置指数函数或运算符。例如,不要在c++中使用pow(x,0.5)或在c++中使用x**0.5python.示例1:输入:x=4输出:2解释:4的平方根是2,所......
  • [题解]P4166 [SCOI2007] 最大土地面积
    P4166[SCOI2007]最大土地面积解法\(1\)-\(O(n^2)\)我们运用调整法,可以证明这个四边形的\(4\)个顶点一定都在凸包的顶点上,具体来说:\(\textbf{Proof:}\)首先我们知道,凸包内,到某条直线距离最大的点一定包括\(1\)个顶点。接下来我们考虑一个凸包内的四边形:我们过它的对角......
  • ABC 363 E - Sinking Land 题解
    用一个优先队列维护和海相邻的位置,每次海面上升就判断一下队列中海拔最低的那个位置会不会被淹没,如果会,就删除,同时它上下左右的位置也是和海相邻的(或者就在海里),把它们加进优先队列里,记得判断一下加入的格子曾经有没有被加入过队列,不要加重复了。点击开DconstintN=1099;int......
  • ABC 363 F - Palindromic Expression 题解
    下文中提到的数字都不包含0,注意把含0的数字特判掉。反转指各个数位倒过来,比如114514反转过后就是415411。注意到,答案一定是这样:数列\(a\)的各个数字相乘,乘以一个回文,再把数列\(a\)倒过来,每个数反转,再相乘。比如:2*57*184481*75*2,其中的数列\(a\)就是:257,中间的回文......
  • Python学习笔记39:进阶篇(二十八)pygame的使用之按键映射及按键失效问题解决
    前言基础模块的知识通过这么长时间的学习已经有所了解,更加深入的话需要通过完成各种项目,在这个过程中逐渐学习,成长。我们的下一步目标是完成pythoncrashcourse中的外星人入侵项目,这是一个2D游戏项目。在这之前,我们先简单学习一下pygame模块。私信我发送消息python资料,......
  • CF819B Mister B and PR Shifts 题解
    题目传送门前置知识权值树状数组及应用解法由[ABC351F]DoubleSum的套路,尝试展开绝对值及\(\min,\max\)。将式子拆开有\(\begin{aligned}&\min\limits_{k=0}^{n-1}\{\sum\limits_{i=1}^{n-k}|a_{i}-(i+k)|+\sum\limits_{i=n-k+1}^{n}|a_{i}-(i-(n-k))|\}\\&=\min......
  • WebGoC题解(11) 627.传声(2019NHOI小乙)
    题目描述 小C节日旅游来到一个农场。农场主John和n个奶牛站在一条水平线上。牛的传递消息是依靠“吼”,牛的吼叫声最远可以传递的距离是50。农场主John首先通知最左边的第一条奶牛(一定会通知),然后奶牛就开始向后吼叫,后面的奶牛如果能听到(和前面吼叫的奶牛距离不超过50),就继续向......
  • 2064:【例2.1】交换值 题解
    题目链接题目描述输入两个正整数\(a\)和\(b\),试交换\(a\)、\(b\)的值(使\(a\)的值等于\(b\),\(b\)的值等于\(a\))。解题思路该题有很多种方法,例如:直接输出\(b\)和\(a\)(偷鸡方法)使用algorithm库的swap函数使用额外变量辅助位运算\(......\)但这道题目放在"运算符和表达式"......
  • CF906C Party题解
    今天来水一波题解……理解题意由于题目意思讲得很清楚,就因为懒惰直接复制了……给你一堆一对对的关系,然后每一个关系对代表两个人认识。然后你每次可以选择一个人i,让i认识的所有人都相互认识,即i把介绍自己所有的朋友给其他人。然后现在问你最少需要选择多少个这样的i,使得所有的......