QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#17947. 巧克力青蛙与踏脚石

통계

$N$ 只巧克力青蛙想要从可可乐园移动到瀚星乐园。可可乐园和瀚星乐园之间有一条河,因为巧克力碰到水会融化,所以为了从可可乐园前往瀚星乐园,必须利用 $N$ 个踏脚石过河。每个踏脚石按顺序编号为 $1$ 到 $N$。为了方便起见,将可可乐园一侧的河岸设为 $0$,瀚星乐园一侧的河岸设为 $N+1$。

巧克力青蛙也按 $1$ 到 $N$ 编号,在 $0$ 号位置从下到上依次堆叠着 $N$ 号到 $1$ 号青蛙。青蛙一次只能移动一只,如果有多只青蛙垂直堆叠在一起,则只有最上面的青蛙可以移动。此外,位于 $i$ 号位置的青蛙在一次移动中只能移动到 $i+1$ 号或 $i+2$ 号位置,不能向后退,且编号较大的青蛙不能叠在编号较小的青蛙上面。

瀚星乐园设有结界,如果青蛙不按照从 $N$ 号到 $1$ 号编号递减的顺序进入,巧克力青蛙身上的魔法就会全部解除。巧克力青蛙们能全部安全地到达瀚星乐园吗?

输入格式

第一行给出一个整数 $N$。$(1 \le N \le 1\,000)$

输出格式

如果所有巧克力青蛙都能安全过河,第一行输出青蛙的移动次数 $M$。该值不需要是最小的。

从第二行开始,按顺序每行输出一次青蛙的移动。当位于 $i$ 号位置最上方的青蛙移动到 $j$ 号位置时,输出 $i$ 和 $j$,用空格分隔。

如果无法过河,则在第一行输出 -1

样例

输入样例 1

2

输出样例 1

4
0 2
0 1
1 3
2 3

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.