Frog and Portal(思维好题)
Frog and Portal
https://hihocoder.com/problemset/problem/1873
描述
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 
一句话题意:给定一个数,用x个斐波那契数列中的数去凑成这个x
用类似下面图的方法去构造

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
ll a[];
ll m;
int ans[][];
void AC(){
int co=;
int k=;
while(m){
int p=upper_bound(a,a+,m)-a;
p--;
ans[co][]=k,ans[co++][]=-p;
m-=a[p];
k+=;
}
cout<<co+<<endl;
for(int i=;i<co;i++){
cout<<ans[i][]<<" "<<ans[i][]<<endl;
}
cout<<ans[co-][]+<<" "<<ans[co-][]+<<endl;
} int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie();
std::cout.tie();
a[]=;a[]=;a[]=;
for(int i=;i<=;i++){
a[i]=a[i-]+a[i-];
}
while(cin>>m){
bool flag=false;
if(m==){
cout<<<<endl;
cout<<"1 1"<<endl;
cout<<"2 1"<<endl;
continue;
}
int ans1,ans2;
AC();
}
return ;
}
Frog and Portal(思维好题)的更多相关文章
- [Gym101982M][思维好题][凸壳]Mobilization
		
[gym101982M][思维好题][凸壳]Mobilization 题目链接 20182019-acmicpc-pacific-northwest-regional-contest-div-1-en ...
 - 土题大战Vol.0 A. 笨小猴 思维好题
		
土题大战Vol.0 A. 笨小猴 思维好题 题目描述 驴蛋蛋有 \(2n + 1\) 张 \(4\) 星武器卡片,每张卡片上都有两个数字,第 \(i\) 张卡片上的两个数字分别是 \(A_i\) 与 ...
 - 思维水题:UVa512-Spreadsheet Tracking
		
Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...
 - hihocoder 1873 ACM-ICPC北京赛区2018重现赛 D Frog and Portal
		
http://hihocoder.com/problemset/problem/1873 时间限制:1000ms 单点时限:1000ms 内存限制:512MB 描述 A small frog want ...
 - 【CodeForces - 707B】Bakery(思维水题)
		
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...
 - CodeForces 604C 【思维水题】`
		
题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...
 - HDU 2674 N!Again(数学思维水题)
		
题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...
 - HDOJ/HDU 1256 画8(绞下思维~水题)
		
Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...
 - 又一道简单题&&Ladygod(两道思维水题)
		
Ladygod Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
 
随机推荐
- jquey XMLHttpRequest cannot load url.Origin null is not allowed by Access-Control-Allow-Origin
			
此篇文章原文地址:http://blog.csdn.net/wangsky2/article/details/22961345 正文: 原文地址:http://stackoverflow.com/qu ...
 - ROS-RouterOS 的license注册级别
			
原文: https://wiki.mikrotik.com/wiki/Manual:CHR#CHR_Licensing https://wiki.mikrotik.com/wiki/Manual:Li ...
 - Microsoft Dynamics CRM 2011 安装完全教程
			
作者:卞功鑫,转载请保留.http://www.cnblogs.com/BinBinGo/p/4302612.html 环境介绍 WINDOWS 2008 R2 Datacenter Microsof ...
 - pycharm下getpass.getpass()卡住
			
pycharm下getpass.getpass()卡住不运行是什么问题 python pycharm 首先声明 下面这几行代码在命令行和eclipse下都能正常运行 import getpass pr ...
 - PCIe Max_Payload_Size 和 Max_Read_Request_Size
			
最近PCIe在SSDFans上镜率挺高,那我们来聊两句MAX_READ_REQUEST_SIZE 和MAX_PAYLOAD_SIZE. 这两个东西都在PCIe Capability Structure ...
 - Latex Error:‘acmart.cls’ not found 解决方案:
			
windows下latex编译ACM论文模板时,出现Latex Error:‘acmart.cls’ not found,解决方案: 首先cd至模板所在目录下,然后运行以下命令: tex acma ...
 - sql 随机取数
			
Sql server: select top 10 * from 表 order by newid()Access: SELECT top 10 * FROM 表 ORDER BY ...
 - Dell Latitude 3490 使用 UEFI+GPT 安装 Win7 x64
			
转载请注明出处!转载请注明出处!转载请注明出处! 公司近期采购了一批笔记本,由于刚好赶上Dell升级换代,原来的3480升级到了3490. 由于部分同事用不惯Win10系统,再加上有些软件不兼容,于是 ...
 - Oracle JOB简例
			
JOB declare jobno number; begin dbms_job.submit( jobno, 'insert into tmptable1 values(1,1);', to_dat ...
 - 49. jdk-6u45-linux-i586.bin安装步骤
			
# chmod u+x ./jdk-6u45-linux-i586.bin 1.# ./jdk-6u45-linux-i586.bin 在按提示输入yes后,jdk被解压到./jdk1.6.0_45目 ...