http://hihocoder.com/problemset/problem/1873

时间限制:1000ms

单点时限:1000ms

内存限制:512MB

描述

A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position 0) and wants to get to the other bank (position 200). Luckily, there are 199 leaves (from position 1 to position 199) on the river, and the frog can jump between the leaves. When at position p, the frog can jump to position p+1 or position p+2.

How many different ways can the small frog get to the bank at position 200? This is a classical problem. The solution is the 201st number of Fibonacci sequence. The Fibonacci sequence is constructed as follows: F1=F2=1;Fn=Fn-1+Fn-2.

Now you can build some portals on the leaves. For each leaf, you can choose whether to build a portal on it. And you should set a destination for each portal. When the frog gets to a leaf with a portal, it will be teleported to the corresponding destination immediately. If there is a portal at the destination, the frog will be teleported again immediately. If some portal destinations form a cycle, the frog will be permanently trapped inside. Note that You cannot build two portals on the same leaf.

Can you build the portals such that the number of different ways that the small frog gets to position 200 from position 0 is M?

输入

There are no more than 100 test cases.

Each test case consists of an integer M, indicating the number of ways that the small frog gets to position 200 from position 0. (0 ≤ M < 232)

输出

For each test case:

The first line contains a number K, indicating the number of portals.

Then K lines follow. Each line has two numbers ai and bi, indicating that you place a portal at position ai and it teleports the frog to position bi.

You should guarantee that 1 ≤ K, ai, bi ≤ 199, and ai ≠ aj if i ≠ j. If there are multiple solutions, any one of them is acceptable.

样例输入

0

1

5

样例输出

2

1 1

2 1

2

1 199

2 2

2

4 199

5 5

思路:

构造题嘛,理论上不停拿数据测AC代码看输出就会做了,因为重要的是怎么构造

可以从2的次方上考虑,假设你在位置x上,求到达位置200,方案数刚好为m,该如何设置传送装置?

    如果当前m是偶数,那么很显然可以在位置x+1上设一个传到x+3的传送门,在位置x+2上设一个传到x+1的传送门,这样的话你无论往前跳2步还是1步都是到达位置x+3上,这样问题就变成了你在位置x+3上,求到达位置200,方案数刚好为m/2,该如何设置传送装置

    如果当前m是奇数,那么很显然可以在位置x+1上设一个直接传到终点的传送门,在位置x+2不设传送门,这样问题就变成了你在位置x+2上,求到达位置200,方案数刚好为m-1,该如何设置传送装置

搞定,注意特判m=1和m=0的情况

我不会推。。。这是CSDN博主「Jaihk662」的方法

斐波那契做法

我好SB

最后修改日期:2019年10月21日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。