当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7233:Arithmetic Subsequence

Special Judge 特殊评判
题目描述
Given an integer array $A=[a_1,a_2,\dots,a_n]$ of length $n$, you need to determine if there exists an integer array $B=[b_1,b_2,\dots,b_n]$ such that the followings hold:
<ol>
<li> The array $B$ is a rearrangement of $A$, i.e., there exists a <strong>permutation</strong> $p=[p_1,p_2,\dots,p_n]$ of size $n$ such that $b_i=a_{p_i}$ for each $1\leq i\leq n$. </li>
<li> The array $B$ doesn't contain any <strong>arithmetic subsequence</strong> of length at least $3$. </li>
</ol>

A sequence $C=[c_1,c_2,\dots,c_k]$ is called an <strong>arithmetic subsequence</strong> of $B$ if and only if the followings are satisfied:
<ol>
<li> There exists a sequence of indices $1\leq i_1\lt i_2\lt\dots\lt i_k\leq N$, such that $c_j=b_{i_j}$ for each $1\leq j\leq k$; </li>
<li> $C$ forms an arithmetic progression, i.e., for each $1
\leq i\leq k-2$, we have $c_{i+2}-c_{i+1}=c_{i+1}-c_{i}$. </li>
</ol>
输入解释
The first line contains an integer $T$ ($1 \le T \le 25$), denoting the number of test cases.

For each test case, the first line contains an integer $n(1\leq n\leq 5000)$, denoting the size of the array $A$.

The next line contains $n$ integers $a_1,a_2,\dots,a_n(1\leq a_i\leq 10^9)$, denoting the elements of the array $A$.
输出解释
For each test case, if no such array $B$ exists, output ''NO''(without quotes) in a line. Otherwise, output ''YES''(without quotes) in a line, and in the next line output a valid array $B$. If there are multiple arrays $B$ that satisfy the requirement, outputting any of them would be considered correct.
输入样例
2
4
3 6 8 9
5
1 1 1 1 1
输出样例
YES
8 6 9 3 
NO

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7233

最后修改于 2022-09-15T06:17:31+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 524288/524288K(Java/Others)