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

建议使用的浏览器:

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

6890:Express Mail Taking

题目描述
Besides on the traditional classes,Baby Volcano also needs to learn how to take the express mails.

Usually express mails are stored in cabinets. In Baby Volcano's school,there are $n$ cabinets in a row,numbered by $1$ to $n$. The distance between two adjacent cabinets is $1$, and the entrance is at the cabinet $1$. Among all $n$ cabinets,the one numbered $k$ is special and it is used to enter the code and open the cabinet door.

Baby Volcano has $m$ express mails to take,the $i$-th is in the cabinet $a_i$.
Two express mails will not be stored in the same cabinet. Also there is no express mail in the cabinet $k$.

To prevent expresses from being stolen, Baby Volcano have to take these express mails one by one, starting at the entrance. Generally, if he wants to take the express mail $i$, he have to walk to cabinet $k$ first to enter the code, and then walks to cabinet $a_i$. After taking the last one,he walks to the entrance.

There are so many express mails to take, so Baby Volcano wants to find a taking order which minimize the distance he walks.
输入解释
The first line contains one integer $T(1 \le T \le 100)$,the number of testcases.

For each test cases,the first line contains three integer $n,m,k(1 \le k \le n \le 10^9,1 \le m < \min(n,10^6))$

The next line contains $m$ integer,the $i$-th stand for $a_i(1 \le a_i \le n,a_i \neq k)$.

The input guarantees that $\sum m \le 2 \times 10^6$

**Note:Because of the large input,it is prefered to use scanf instead of cin.**
输出解释
For each test case,Output a single line contains one integer,representing for the minimal walking distance.
输入样例
2
10 2 5
6 7
10 2 5
3 4
输出样例
14
10
来自杭电HDUOJ的附加信息
Recommend IceyWang

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

源链接: HDU-6890

最后修改于 2020-10-25T23:35:18+00:00 由爬虫自动更新

共提交 0

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