QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 256 MB Puntuación total: 100

#15650. 纸牌魔术

Estadísticas

Mahsa 已经练习洗牌好几个月了。今晚,她终于决定邀请朋友们过来,展示她的新技能。于是她拿出一副有 $2n$ 张牌的扑克牌,在不改变牌组顺序的情况下向朋友们展示了牌面,并让某人选择牌组中的两个位置 $i$ 和 $j$。然后,她告诉大家,她将仅通过两种洗牌方式,将处于第 $i$ 个位置的牌移动到第 $j$ 个位置。

假设牌组中的牌为 $\langle c_1, c_2, \dots, c_{2n} \rangle$。Mahsa 可以根据需要执行以下两种洗牌操作任意次:

  • Riffle:将牌分为两部分 $\langle c_1, \dots, c_n \rangle$ 和 $\langle c_{n+1}, \dots, c_{2n} \rangle$,并生成 $\langle c_1, c_{n+1}, c_2, c_{n+2}, \dots, c_n, c_{2n} \rangle$。
  • Scuffle:从 $\langle c_1, c_2, \dots, c_{2n} \rangle$ 生成 $\langle c_2, c_1, c_4, c_3, \dots, c_{2n}, c_{2n-1} \rangle$。

帮助 Mahsa 找出她所需的最少洗牌次数,剩下的事情她自己会搞定。

输入格式

输入仅包含一行,其中有三个空格分隔的整数 $n$,$i$ 和 $j$($1 \le n \le 10^5$ 且 $1 \le i, j \le 2n$)。

输出格式

输出一个整数,表示将第 $i$ 张牌移动到第 $j$ 个位置所需的最少洗牌次数。如果无法做到,则输出 -1

样例

输入样例 1

4 3 8

输出样例 1

3

输入样例 2

5 4 1

输出样例 2

5

输入样例 3

1 1 1

输出样例 3

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.