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 ...
随机推荐
- H-Index II @python
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...
- ubuntu 查看系统配置
1, 主板信息 .查看主板的序列号 -------------------------------------------------- #使用 命令 dmidecode | grep -i 'ser ...
- python3 tkinter
https://morvanzhou.github.io/tutorials/python-basic/tkinter/ 李导师推荐的.非常感谢.非常棒的视频教程!!! 只不过里面的教程视频是yout ...
- UML 中关系图的解说
最近在教软件工程项目实践,就又仔细了解了下UML中各种关系的意义,虽然有点简单,但是有些概念还是经常被混淆的,写在这里是为了加深印象. 关系列表: 继承关系(Generalization): 实现关系 ...
- 关于有些邮件可以在http上发送成功但是https不能发送成功一个思路方法
关于有些邮件可以在http上发送成功但是https不能发送成功 其实如果是单纯的发送邮件,是没问题 今天一个客户出现这个问题,进行排查 他的邮件发送是任务制的, 是通过CURL请求的, 我估计她的CU ...
- 微擎框架小程序 uitl
获取用户信息 util.getUserInfo(callback) 获取成功后会将用户信息写入到缓存中,如果指定了回调函数,则会调用回调函数 callback 获取成功后的回调函数 示例 var ap ...
- 谈谈 Python 程序的运行原理
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,谈谈 Python 程序的运行原理 这篇文章准确说是『Python 源码剖析』的 ...
- leetcode349
public class Solution { public int[] Intersection(int[] nums1, int[] nums2) { var list1 = nums1.ToLi ...
- leetcode506
public class Solution { public string[] FindRelativeRanks(int[] nums) { var list = nums.OrderByDesce ...
- 使用AngularJS处理单选框和复选框的简单方法
在复选框中,可以绑定ng-model给false或者true值,即可选中或清除选中状态 如下图 而在单选框里就相对复杂一点,单选框要选中一个,就要给相同的name属性,然后绑定相同的ng-model, ...