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 ...
随机推荐
- windows下查看端口被哪个进程占用
1.netstat -anp|findstr "port" 得到进程id 2.tasklist|findstr "pid" 得到是进程名
- [UE4]ue4 FString 中文乱码问题
使用FString出现乱码,最简单的情况,FString Str = "你好"; 这时候就会出现乱码,解决方法是改成这样 FString Str = TEXT("你好&q ...
- 操他妈的,jquery1.4以上不能用toggle()轮流切换函数
query 1.9里面已经删除了toggle(fn1, fn2)函数 (2013-05-07 13:44:27) 转载▼ 标签: it 分类: js jquery 1.9里面已经删除了toggle(f ...
- pig和mysql脚本对比
测试数据位于:/home/hadoop/luogankun/workspace/sync_data/pig dept和emp表来源自oracle数据库自带的表 dept.txt ACCOUNTING ...
- php 编程笔记分享
php获取POST数据的三种方法php 图片加水印源代码php+ajax+json的一个最简单实例php 汉字转拼音源码php遍历目录,生成目录下每个文件的md5值并写入到结果文件中php实现linu ...
- Mysql主从同步在线实施步骤【适合大数据库从库配置】
Mysql主从同步在线实施步骤[适合大数据库从库配置] MySQL的主从搭建大家有很多种方式,传统的mysqldump方式是很多人的选择之一,但比较适合在新实例中实施,对于较大的数据库则存在停机等不可 ...
- ORA:01745 无效的主机 绑定变量名
原因是:mybatis中的mapping映射时,sql语句中忘了加逗号,且逗号处有换行
- PyQt5系列教程(九)QInputDialog的使用
软硬件环境 Ubuntu 15.10 32bit Python 3.5.1 PyQt 5.5.1 前言 输入框是界面开发中非常常见的控件,本文就来看看PyQt5中QInputDialog的使用 实例 ...
- tornado-通过判断后台数据限制登陆--简单的
import tornado.ioloop import tornado.web import tornado.httpserver # 非阻塞 import tornado.options # 提供 ...
- SqlServer——触发器
一:触发器基本知识 1.首先必须明确以下几点: 触发器是一种特殊的存储过程,但没有接口(输入输出参数),在用户执行Inserted.Update.Deleted 等操作时被自动触发: 当触发的SQL ...