今天下午刚起来眼睛就比較涨,,并且还有点恶心,唉。结果一直不在状态。并且这个题太坑了。。

。。

点击此处即可传送 Hit 2255

Maybe ACMers of HIT are always fond of fibonacci numbers, because it is so beautiful. Don't you think so? At the same time, fishcanfly always likes to change and this time he thinks about the following series of numbers which you can guess is derived from the definition of fibonacci number. 

The definition of fibonacci number is: 

f(0) = 0, f(1) = 1, and for n>=2, f(n) = f(n - 1) + f(n - 2) 

We define the new series of numbers as below: 

f(0) = a, f(1) = b, and for n>=2, f(n) = p*f(n - 1) + q*f(n - 2),where p and q are integers. 

Just like the last time, we are interested in the sum of this series from the s-th element to the e-th element, that is, to calculate ."""" 

Great!Let's go! 

Input 

The first line of the input file contains a single integer t (1 <= t <= 30), the number of test cases, followed by the input data for each test case. 

Each test case contains 6 integers a,b,p,q,s,e as concerned above. We know that -1000 <= a,b <= 1000,-10 <= p,q <= 10 and 0 <= s <= e <= 2147483647. 

Output 

One line for each test case, containing a single interger denoting S MOD (10^7) in the range [0,10^7) and the leading zeros should not be printed. 

Sample Input
2
0 1 1 -1 0 3
0 1 1 1 2 3 Sample Output
2
3

题目大意:

就是给你好几个数,分别表示什么意思,看题即可了;

解题思路:矩阵乘法,递推公式,

注意了,注意了,千万不要用全局变量

if(ans < 0)

ans += mod;

printf(“%lld\n”,ans);

}

return 0;

}

!!!!

!!

/*
2015 - 8 - 14 下午
Author: ITAK 今天很很的不顺心啊。。。。 今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标。不断地超越自己。
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 3;
const int mod = 1e7;
typedef long long LL;
typedef struct
{
LL m[maxn][maxn];
} Matrix;
// LL a, b, s, e, q, p;千万不要用全局变量
Matrix P = {0,0,0,
1,0,0,
0,0,1
};
Matrix I = {1,0,0,
0,1,0,
0,0,1
};
Matrix matrix_mul(Matrix a, Matrix b)
{
int i, j, k;
Matrix c;
for(i=0; i<maxn; i++)
{
for(j=0; j<maxn; j++)
{
c.m[i][j] = 0;
for(k=0; k<maxn; k++)
{
a.m[i][k] = (a.m[i][k]%mod + mod) % mod;
b.m[k][j] = (b.m[k][j]%mod + mod) % mod;
c.m[i][j] += (a.m[i][k] * b.m[k][j]) % mod;
}
c.m[i][j] = (c.m[i][j]%mod + mod) % mod;
}
}
return c;
} Matrix quick_mod(LL m)
{
Matrix ans = I, b = P;
while(m)
{
if(m & 1)
ans = matrix_mul(ans, b);
m >>= 1;
b = matrix_mul(b, b);
}
return ans;
}
int main()
{
int t;
LL a, b, q, p, e, s;
scanf("%d",&t);
while(t--)
{ Matrix tmp1, tmp2;
LL ans, ans1, ans2;
cin>>a>>b>>p>>q>>s>>e;
P.m[0][0]=p;
P.m[0][1]=q;
P.m[2][0]=p;
P.m[2][1]=q;
if(s-2 > 0)
{
tmp1 = quick_mod(s-2);
ans1 = (b*tmp1.m[2][0])%mod + (a*tmp1.m[2][1])%mod + ((a+b)*tmp1.m[2][2])%mod;
}
else
{
if(s == 0)
ans1 = 0;
if(s == 1)
ans1 = a;
if(s == 2)
ans1 = a + b ;
}
if(e-1 > 0)
{
tmp2 = quick_mod(e-1);
ans2 = (b*tmp2.m[2][0])%mod + (a*tmp2.m[2][1])%mod + ((a+b)*tmp2.m[2][2])%mod;
}
else
{
if(e == 0)
ans2 = a;
else
ans2 = b+a;
}
ans1 = (ans1%mod+mod) % mod;
ans2 = (ans2%mod+mod) % mod;
//cout<<ans1<<" "<<ans2<<" ";
ans = (ans2 - ans1 + mod) % mod;
if(ans < 0)
ans += mod;
printf("%lld\n",ans);
}
return 0;
}

Hit 2255 Not Fibonacci的更多相关文章

  1. HIT 2255 Not Fibonacci(矩阵高速幂)

    #include <iostream> #include <cstdio> #include <cstring> using namespace std; cons ...

  2. fibonacci数列的和取余(2)

    Maybe ACMers of HIT are always fond of fibonacci numbers, because it is so beautiful. Don't you thin ...

  3. 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找

    今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...

  4. #26 fibonacci seqs

    Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...

  5. 关于java的递归写法,经典的Fibonacci数的问题

    经典的Fibonacci数的问题 主要想展示一下迭代与递归,以及尾递归的三种写法,以及他们各自的时间性能. public class Fibonacci { /*迭代*/ public static ...

  6. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  7. 斐波拉契数列(Fibonacci) 的python实现方式

    第一种:利用for循环 利用for循环时,不涉及到函数,但是这种方法对我种小小白来说比较好理解,一涉及到函数就比较抽象了... >>> fibs = [0,1] >>&g ...

  8. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  9. fibonacci数列(五种)

    自己没动脑子,大部分内容转自:http://www.jb51.net/article/37286.htm 斐波拉契数列,看起来好像谁都会写,不过它写的方式却有好多种,不管用不用的上,先留下来再说. 1 ...

随机推荐

  1. 【POI 2007】 山峰和山谷

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1102 [算法] 广度优先搜索 [代码] #include<bits/stdc+ ...

  2. 使用asp.net 开发的一个东平人才网招聘程序

    本人用asp.net 工作已经一两年时间了,在单位一般是做管理系统类的开发,针对的客户大都是政府机关,所以都是内网系统,虽然有成就感,但是无法再互联网上展示.虽然技术一般,但还是希望自己做一个网站在互 ...

  3. ADO.NET改进防注入

    static void Main1(string[] args) { //用户输入一个需要查询的条件 car表 Console.WriteLine("请输入"); string c ...

  4. 使用Micrisoft.net设计方案 第二章组织模式

    第二章组织模式 模式不仅依赖于它所包含的更小模式,同时也依赖包含它的更大的模式.它是描述复杂软件的系统方法. 本章的目标是让我们了解以下问题: 1.如何标识模式与模式的关系 2.如何把模式组织成模式集 ...

  5. CI中的超级对象

    CI中的超级对象就是当前控制器对象,它提供了很多属性,可以通过var_dump($this)打印所有的超级对象: load可以理解为一个加载器,加载了很多功能,可以理解为当你使用 $this -> ...

  6. 组装自己的tesla超级计算机

    原文链接:blog.csdn.net/xqj198404/article/details/20016279 NVIDIA链接:http://www.nvidia.cn/object/tesla_bui ...

  7. 优动漫PAINT发展历程和主要功能

    优动漫PAINT也就是我们常说的clip studio paint(CSP)的中文版本,它是一款功能强大的动漫绘图软件.经过五年的成长,优动漫PAINT经历了从青涩到成熟的发展过程,随着软件更多功能的 ...

  8. Delphi中实现文件拷贝的三种方法

    1.调用API函数procedure CopyFile(FromFileName,ToFileName:string);varf1,f2:file;BeginAssignFile(f1,FromFil ...

  9. vc++实例创建简单窗体

    #include<windows.h>#include<stdio.h>LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPAR ...

  10. Ubuntu终端命令行缩短显示路径

    平时我们使用linux终端命令行的时候,常常会被一个问题困扰,那就是文件路径过长, 有时候甚至超过了一行,这样看起来非常别扭,其实只要两步就可以解决这个问题: 1,修改.bashrc文件(用户根目录下 ...