ZOJ 3702 Gibonacci number 2017-04-06 23:28 28人阅读 评论(0) 收藏
Gibonacci number
Time Limit: 2 Seconds Memory Limit: 65536 KB
In mathematical terms, the normal sequence F(n) of Fibonacci numbers is defined by the recurrence relation
F(n)=F(n-1)+F(n-2)
with seed values
F(0)=1, F(1)=1
In this Gibonacci numbers problem, the sequence G(n) is defined similar
G(n)=G(n-1)+G(n-2)
with the seed value for G(0) is 1 for any case, and the seed value for G(1) is a random integer t, (t>=1).
Given the i-th Gibonacci number value G(i), and the number j, your task is to output the value for G(j)
Input
There are multiple test cases. The first line of input is an integer T < 10000 indicating the number of test cases. Each test case contains 3 integers i, G(i) and j.
1 <= i,j <=20, G(i)<1000000
Output
For each test case, output the value for G(j). If there is no suitable value for t, output -1.
Sample Input
4
1 1 2
3 5 4
3 4 6
12 17801 19
Sample Output
2
8
-1
516847
题目的意思是给出Gibonacci某一项的值,求出给定项
设G(1)=x;
则G(0)=1,G(1)=x,G(2)=1+x,G(3)=2x+1,G(4)=3x+2;
我们发现x的系数和常数符合斐波那契数列,推导公式即可
注意G(1)=0的时候输出-1;
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF=0x3f3f3f3f; int a[30],b[30]; void init()
{
a[0]=0,a[1]=1;
b[0]=1,b[1]=0;
for(int i=2;i<=22;i++)
a[i]=a[i-1]+a[i-2],b[i]=b[i-1]+b[i-2];
} int main()
{
init();
int t;
scanf("%d",&t);
while(t--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
y-=b[x];
if(y%a[x]!=0||y==0) {printf("-1\n");continue;}
int xx=y/a[x];
printf("%lld\n",1LL*xx*a[z]+b[z]);
}
return 0;
}
ZOJ 3702 Gibonacci number 2017-04-06 23:28 28人阅读 评论(0) 收藏的更多相关文章
- Number of Containers(数学) 分类: 数学 2015-07-07 23:42 1人阅读 评论(0) 收藏
Number of Containers Time Limit: 1 Second Memory Limit: 32768 KB For two integers m and k, k is said ...
- ZOJ2482 IP Address 2017-04-18 23:11 44人阅读 评论(0) 收藏
IP Address Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose you are reading byte streams fr ...
- 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏
动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...
- NYOJ-235 zb的生日 AC 分类: NYOJ 2013-12-30 23:10 183人阅读 评论(0) 收藏
DFS算法: #include<stdio.h> #include<math.h> void find(int k,int w); int num[23]={0}; int m ...
- HDU 2034 人见人爱A-B 分类: ACM 2015-06-23 23:42 9人阅读 评论(0) 收藏
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 2035 人见人爱A^B 分类: ACM 2015-06-22 23:54 9人阅读 评论(0) 收藏
人见人爱A^B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU2033 人见人爱A+B 分类: ACM 2015-06-21 23:05 13人阅读 评论(0) 收藏
人见人爱A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏
SCU - 4440 Rectangle Time Limit: Unknown Memory Limit: Unknown 64bit IO Format: %lld & %llu ...
- HDU2680 Choose the best route 最短路 分类: ACM 2015-03-18 23:30 37人阅读 评论(0) 收藏
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
随机推荐
- vs2010 光盘镜像免输入KEY 序列号
用ULTRA ISO打开VS2010 ISO文件.找到\Setup\setup.sdb,提取出来编辑.用记事本打开.搜索到[Product Key]配置节,如果下面为空,补上KEY.如果是试用KEY, ...
- GCC 三
前记: 经常浏览博客园的同学应该会觉得本文有标题党之嫌,这个标题的句式来自于MiloYip大牛的大作<C++强大背后>,在此,向Milo兄致意. GCC,全称GNU Compiler Co ...
- Bootstrap-CL:超大屏幕
ylbtech-Bootstrap-CL:超大屏幕 1.返回顶部 1. Bootstrap 超大屏幕(Jumbotron) 本章将讲解 Bootstrap 支持的另一个特性,超大屏幕(Jumbotro ...
- Office 2016激活教程(附KMS激活软件)
首先下载office 2016办公软件文件名:cn_office_professional_plus_2016_x86_x64_dvd_6969182.isoSHA1:277926A41B472EE3 ...
- 深入浅出HTTPS工作原理(转载)
转载自: https://blog.csdn.net/wangtaomtk/article/details/80917081 深入浅出HTTPS工作原理 HTTP协议由于是明文传送,所以存在三大风险: ...
- hive基本结构与数据存储
一.Hive简介 Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能.还可以将 SQL 语句转换为 MapReduce 任务进行运行,通过自 ...
- vconsole使用
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- Sonar及其eclipse插件的安装 详细 http://www.importnew.com/10017.html
参考:http://www.importnew.com/10017.html
- C++Builder 代码编辑器 回车自动补充括弧
两大问题 括弧和折叠 一.括弧 XE7,回车,自动补充括弧} 好用,有时候不准确,代码量多,不知道什么原因就引起错误,总是多一个括弧,一回车就加一个括弧,都不敢回车写代码了,怎么关闭此选项? 找到了, ...
- mysql 百万级数据库优化方案
https://blog.csdn.net/Kaitiren/article/details/80307828 一.百万级数据库优化方案 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 wher ...