CF2164A.Sequence Game
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an integer sequence of length n denoted as a1,a2,…,an and an integer x.
You can perform the following operation: select two adjacent numbers ai and ai+1 and replace them with an integer y, which satisfies min(ai,ai+1)≤y≤max(ai,ai+1). After the replacement, the original ai and ai+1 are removed from the sequence, and the elements are renumbered from 1 to n−1.
For example, for a=[1,2,4,5] you can select a2=2 and a3=4, and replace them with 3. After that, a becomes [1,3,5]. However, you cannot select a1=1 and a2=2 and replace them with 3 (since y is bigger than max(ai,ai+1), nor can you select a1=1 and a3=4 (the selected numbers should be adjacent).
Clearly, after performing n−1 operations, only one number will remain. The question is whether this final number can be exactly equal to x.
给定一个长度为 n 的整数序列 a1,a2,…,an 和一个整数 x。
你可以执行如下操作:选择两个相邻的数 ai 和 ai+1,并用一个整数 y 替换它们,其中 y 满足 min(ai,ai+1)≤y≤max(ai,ai+1)。替换后,原 ai 和 ai+1 从序列中被移除,剩余元素重新编号为 1 到 n−1。
例如,对 a=[1,2,4,5],你可以选择 a2=2 和 a3=4,并用 3 替换它们;之后 a 变为 [1,3,5]。但你不能选择 a1=1 和 a2=2 并用 3 替换它们(因为 y 超过了 max(ai,ai+1)),也不能选择 a1=1 和 a3=4(所选数字必须相邻)。
显然,经过 n−1 次操作后,序列中将仅剩一个数。问题是:这个最终的数能否恰好等于 x?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases T (1≤T≤500). The description of the test cases follows.
The first line of each test case contains one integer n (1≤n≤100).
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109).
The third line of each test case contains one integer x (−109≤x≤109).
每个测试包含多个测试用例。第一行包含测试用例的数量 T(1≤T≤500)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)。
每个测试用例的第三行包含一个整数 x(−109≤x≤109)。
输出格式
For each test case, output "YES" (without quotes) if the final number can be exactly equal to x, and "NO" otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
对于每个测试用例,如果最终的数字可以恰好等于 x,则输出 "YES"(不带引号);否则输出 "NO"。
您可以以任意大小写形式输出 "YES" 和 "NO"(例如,字符串 "yES"、"yes" 和 "Yes" 均会被识别为肯定回答)。
输入输出样例
输入#1
3 3 2 7 5 4 5 -1 3 7 -9 -2 8 6 1 -1 -4 5 1 -4 -2
输出#1
YES NO YES
说明/提示
In the first test case, you can first select a2=7 and a3=5, and replace them with 6. After that, a becomes [2,6]. Now you can select a1=2 and a2=6, and replace them with 4.
In the second test case, it can be shown that the final number can never be 8.
在第一个测试用例中,你可以首先选择 a2=7 和 a3=5,并将它们替换为 6。此后,数组 a 变为 [2,6]。现在你可以选择 a1=2 和 a2=6,并将它们替换为 4。
在第二个测试用例中,可以证明最终得到的数永远不可能是 8。
输入解题思路,AI测评打分。不知道怎么写?