Frog and Portal HihoCoder - 1873 (二进制拆分)

探讨一只青蛙如何通过跳跃和利用传送门从河的一侧到达另一侧的问题,涉及到经典的斐波那契数列和二进制拆分算法,解决特定方案数量下的传送门布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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?

Input

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)

Output

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.

Sample Input

0
1
5

Sample Output

2
1 1
2 1
2
1 199
2 2
2
4 199
5 5

题意 :一只青蛙想从0 到 200 ,1 到 199 都有荷叶  ,你可以放置传送门   让 A传送到B  如果 A到A 那么形成自环                

  现在给你青蛙到200应该有的方案数 ,求怎么放置传送门

解 :二进制拆分 如果需要该位的二进制那么连到 199 如果不需要则自环

位置1234567891011121314
方案数/传送门自环/连1991122自/1992244自/1994

 

#include <stdio.h>
#include <algorithm>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    while(~scanf("%lld",&n))
    {
        printf("65\n");
        if(n&(1ll<<0)) printf("1 199\n");
        else printf("1 1\n");
        for(ll i=1;i<32;i++)
        {
          printf("%lld %lld\n",5+(i-1)*6,5+(i-1)*6);
          if(n&(1ll<<i)) printf("%lld 199\n",7+(i-1)*6);
          else printf("%lld %lld\n",7+(i-1)*6,7+(i-1)*6);
        }
        printf("197 197\n");
        printf("198 198\n");
    }
}
 
 
 
安卓adb驱动工具包是什么?adb驱动是Android设备(如手机)连接PC时所需要的驱动程序,可用于安卓手机解锁操作,解锁后手机就能够进行刷机啦,非常的实用。google提供,总共包括4个文件,分别为adb.exe,AdbWinApi.dll,AdbWinUsbApi.dll和fastboot.exe,     使用方法如下: 1、下载解压,如放在D:\adb_tools-2.0目录。 2、手机进入fastboot模式: 先将手机关机,然后同时按下音量下键以及开机键,并保持10秒钟以上时间,就可以进入fastboot模式。 3、连接手机和PC机: 使用USB线连接手机和电脑,依次点击开始菜单--运行cmd进入dos系统,进入ADB安装目录,确认手机电脑连接正常,确认方法为在命令行窗口输入fastboot devices,可以看到正常连接的信息,如:9e42530e fastboot。     4、执行解锁命令: 在电脑命令行窗口中输入fastboot oem unlock ****************,*号为16位解锁密码,例如:fastboot oem unlock 1234567812345678。     5、等待手机解锁完成:  输入解锁密码后,手机将自动重启,如果输入密码正确,手机将进入恢复出厂设置模式。恢复出厂设置完成后,手机自动重启,进入待机界面,完成整个解锁操作。 6、查询手机解锁是否成功: 在电脑的命令行窗口中输入fastboot oem get-bootinfo,将显示当前手机bootloader的状态信息,例如“Bootloader Lock State: LOCKED”,表示bootloader仍处于锁定状态。如果显示“Bootloader Lock State: UNLOCKED”,表示手机已经解锁,可以进行刷机操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值