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 ...
随机推荐
- C#:进程、线程、应用程序域(AppDomain)与上下文分析
进程 进程是操作系统用于隔离众多正在运行的应用程序的机制.在.Net之前,每一个应用程序被加载到单独的进程中,并为该进程指定私有的虚拟内存.进程不能直接访问物理内存,操作系统通过其它的处理把这 ...
- 数据库比较工具DBCompareTool for Oracle 0.2.5发布
迁移数据库sql to oracle http://www.oracle.com/technetwork/cn/database/migration/connect-sqlserver-1945229 ...
- OneProxy常用参数说明
5.2.OneProxy常用参数说明 OneProxy的所有可用参数可通过oneproxy --help-all查看.所有参数均可以写入文件中,由OneProxy启动时加载 5.2.1.基本参数 -- ...
- Visual Studio环境变量、工作目录、vc++目录、 命令等 的配置和作用
在调试 Visual Studio 2008 程序时,经常有一些动态链接库(即 dll 文件)需要加载到工程里,这样才能依赖第三方库进行程序调试. 这些动态链接库,往往都是测试版本或是开发中的版本,或 ...
- 黄聪:VPS服务器如何配置PHP.ini解决wordpress使用WP-Mail-SMTP插件发邮件出现Could not connect to SMTP host的解决办法
1.首先是WP-Mail-SMTP的下载地址:http://wordpress.org/plugins/wp-mail-smtp/ 2.出现Could not connect to SMTP host ...
- [DP题]采药
1775:采药 总时间限制:1000ms内存限制:65536kB 描述 辰辰是个很有潜能.天资聪颖的孩子,他的梦想是称为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给 ...
- 租用游艇(简单区间dp)
租用游艇 时间限制: 1 Sec 内存限制: 128 MB提交: 1 解决: 1[提交][状态][讨论版][命题人:quanxing] 题目描述 长江游艇俱乐部在长江上设置了n 个游艇出租站1,2 ...
- 6.2笔记-DQL语句查询数据库
一.DQL语句 1.常量列 SELECT `StudentName` AS 姓名, `Address` AS 地址, '北京信息中心' AS 学校名称 FROM `student`; 2.常用函数 聚 ...
- hive 创建/删除/截断 表(翻译自Hive wiki)
这里罗列常用操作,更多参考 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL- ...
- 页面白屏并且报错PHP Parse error: syntax error, unexpected end of file in 试了很久总算解决了
页面白屏并且报错PHP Parse error: syntax error, unexpected end of file in 试了很久 啥短标记,打开,都试了 最简单的办法 是重新建立一个文件, ...