CF2060C.Game of Mathletes
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob are playing a game. There are n (n is even) integers written on a blackboard, represented by x1,x2,…,xn. There is also a given integer k and an integer score that is initially 0. The game lasts for 2n turns, in which the following events happen sequentially:
- Alice selects an integer from the blackboard and erases it. Let's call Alice's chosen integer a.
- Bob selects an integer from the blackboard and erases it. Let's call Bob's chosen integer b.
- If a+b=k, add 1 to score.
Alice is playing to minimize the score while Bob is playing to maximize the score. Assuming both players use optimal strategies, what is the score after the game ends?
爱丽丝和鲍勃正在玩一个游戏。黑板上写有 n(n 为偶数)个整数,记为 x1,x2,…,xn。此外给定一个整数 k,以及一个初始值为 0 的分数。游戏共进行 2n 轮,每轮依次发生以下事件:
- 爱丽丝从黑板上选择一个整数并将其擦除。记爱丽丝选择的整数为 a。
- 鲍勃从黑板上选择一个整数并将其擦除。记鲍勃选择的整数为 b。
- 若 a+b=k,则将分数加 1。
爱丽丝的目标是最小化最终分数,而鲍勃的目标是最大化最终分数。假设双方均采用最优策略,游戏结束时的分数是多少?
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and k (2≤n≤2⋅105,1≤k≤2⋅n, n is even).
The second line of each test case contains n integers x1,x2,…,xn (1≤xi≤n) — the integers on the blackboard.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 k(2≤n≤2⋅105,1≤k≤2⋅n,且 n 为偶数)。
每个测试用例的第二行包含 n 个整数 x1,x2,…,xn(1≤xi≤n)—— 黑板上的整数。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output the score if both players play optimally.
对于每个测试用例,输出双方均采取最优策略时的得分。
输入输出样例
输入#1
4 4 4 1 2 3 2 8 15 1 2 3 4 5 6 7 8 6 1 1 1 1 1 1 1 16 9 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
输出#1
2 1 0 4
说明/提示
In the first test case, one way the game may go is as follows:
- Alice selects 1 and Bob selects 3. The score increases as 1+3=4. Now the two integers remaining on the blackboard are 2 and 2.
- Alice and Bob both select 2. The score increases as 2+2=4.
- The game ends as the blackboard now has no integers.
In the third test case, it is impossible for the sum of Alice and Bob's selected integers to be 1, so we answer 0.
Note that this is just an example of how the game may proceed for demonstration purposes. This may not be Alice or Bob's most optimal strategies.
在第一个测试用例中,游戏的一种可能进行方式如下:
- 爱丽丝选择 1,鲍勃选择 3。得分增加为 1+3=4。此时黑板上剩余的两个整数为 2 和 2。
- 爱丽丝和鲍勃均选择 2。得分增加为 2+2=4。
- 游戏结束,因为黑板上已无整数。
在第三个测试用例中,爱丽丝与鲍勃所选整数之和不可能为 1,因此答案为 0。
注意:以上仅为演示游戏可能如何进行的一个示例。这未必是爱丽丝或鲍勃的最优策略。
输入解题思路,AI测评打分。不知道怎么写?