Water Problem

Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)
Total Submissions:1228   Accepted:121

[Submit][Status][Discuss]

Description

函数 f:Z+→Z

。已知 f(1),f(2) 的值,且对于任意 x>1,有 f(x+1)=f(x)+f(x−1)+sin(πx2)

求 f(n)

的值。

Input

多组数据。(数据组数 T≤100

每组数据包含 3

个不超过 109 的正整数,分别代表 f(1),f(2) 和 n

的值。

Output

输出 f(n)mod(109+7)

。每组输出末尾有换行符。

Sample Input

1 2 3
1 2 5

Sample Output

3
7
【分析】矩阵快速幂裸题。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
using namespace std;
typedef long long ll;
const long long mod = 1e9+;
const long long N = ;
ll f1,f2;
int n;
struct Fast_Matrax
{ ll a[N][N];
Fast_Matrax()
{
memset(a,,sizeof(a));
}
void init()
{
for(int i=;i<N;i++)
for(int j=;j<N;j++)
a[i][j]=(i==j);
}
Fast_Matrax operator * (const Fast_Matrax &B)const
{
Fast_Matrax C;
for(int i=;i<N;i++)
for(int k=;k<N;k++)
for(int j=;j<N;j++)
C.a[i][j]=(C.a[i][j]+1LL*a[i][k]*B.a[k][j]%mod+mod)%mod;
return C;
}
Fast_Matrax operator ^ (const int &t)const
{
Fast_Matrax A=(*this),res;
res.init();
int p=t;
while(p)
{
if(p&)res=res*A;
A=A*A;
p>>=;
}
return res;
}
}ans,tmp,x;
int main()
{
while(~scanf("%lld%lld%d",&f1,&f2,&n))
{
x.a[][]=f2;x.a[][]=f1;x.a[][]=,x.a[][]=;
if(n==)printf("%lld\n",f1);
else if(n==)printf("%lld\n",f2);
else
{
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=-;
tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;tmp.a[][]=;
ans=x*(tmp^(n-));
printf("%lld\n",ans.a[][]);
}
}
return ;
}
												

dutacm.club Water Problem(矩阵快速幂)的更多相关文章

  1. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  3. 焦作网络赛L-Poor God Water【矩阵快速幂】

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  4. bnuoj 16493 Just Pour the Water(矩阵快速幂)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=16493 [题解]:矩阵快速幂 [code]: #include <cstdlib> #i ...

  5. zoj 2974 Just Pour the Water (矩阵快速幂,简单)

    题目 对于案例的解释请见下图: 这道要变动提取一下矩阵,之后就简单了 具体解释可看代码: #include <string.h> #include <stdio.h> #inc ...

  6. ZOJ 2794 Just Pour the Water 【矩阵快速幂】

    给你n个杯子,每次有特定的到水规则,倒m次请问最后每个被子里还有多少水 我们很容易发现每次变化的规则相同,那么可以set 一个矩阵存放 然后多次倒水就相当于矩阵相乘,在m 范围达到(1<= M  ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(矩阵快速幂,BM)

    https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中 ...

  8. HDU - 3521 An easy Problem(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=3521 题意 对于矩阵A,求e^A的值. 分析 这个定眼一看好像很熟悉,就是泰勒展开,可惜自己的高数已经还给老师了 ...

  9. A Simple Math Problem(矩阵快速幂)----------------------蓝桥备战系列

    Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 ...

随机推荐

  1. PowerMock

    EasyMock 以及 Mockito 都因为可以极大地简化单元测试的书写过程而被许多人应用在自己的工作中,但是这 2 种 Mock 工具都不可以实现对静态函数.构造函数.私有函数.Final 函数以 ...

  2. 运动目标前景检测之ViBe源代码分析

    一方面为了学习,一方面按照老师和项目的要求接触到了前景提取的相关知识,具体的方法有很多,帧差.背景减除(GMM.CodeBook. SOBS. SACON. VIBE. W4.多帧平均……).光流(稀 ...

  3. Grep basic and practice

    定义:Grep (Globally search for the reqular expression and print out the line). 好处:Grep 在执行时不需要先调用编辑程序, ...

  4. 100个Swift必备Tips(第二版)

    100个Swift必备Tips(第二版) 新年第一天,给大家一本电子书,希望新的一年里,步步高升. GitHub

  5. Android百度定位地图使用--文章集锦

    Android百度定位API使用方法 Android百度地图开发(一)之初体验 AndroidNote013.在百度地图上画出轨迹 Android学习笔记之百度地图(分条目覆盖物:ItemizedOv ...

  6. session超时设置+超时页面跳转

    session超时设置,方法有三种: (1)在主页面或者公共页面中加入:session.setMaxInactiveInterval(600);参数600单位是秒,即在没有10分钟活动后,sessio ...

  7. 遍历文档内容,得到HTML层级结构

    嗯..没发现有写好的,那就自己写一个,刚好自己今天看了DOM操作的知识点,巩固一下. HTML可以表示为一个层次结构,生成的DOM Tree 就是类似与数据结构中的树一样,每个DOM节点都有它的chi ...

  8. java 获取当前应用程序路径

    package javaapplication1; import javax.swing.JOptionPane; /** * * @author Administrator */ public cl ...

  9. python2.7字典转换成json时中文字符串变成unicode的问题:

    参考:http://blog.csdn.net/u014431852/article/details/53058951 编码问题: python2.7字典转换成json时中文字符串变成unicode的 ...

  10. unicode字符串解码显示

    # encoding: utf-8 ''' unicode字符串解码显示 ''' import sys reload(sys) sys.setdefaultencoding('utf-8') a = ...