dutacm.club Water Problem(矩阵快速幂)

news/2024/7/8 1:44:48

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(x1)+sin(πx2)

f(n)

的值。

Input

多组数据。(数据组数 T100

每组数据包含 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+7;
const long long N = 4;
ll f1,f2;
int n;
struct Fast_Matrax
{
 
    ll a[N][N];
    Fast_Matrax()
    {
        memset(a,0,sizeof(a));
    }
    void init()
    {
        for(int i=0;i<N;i++)
            for(int j=0;j<N;j++)
                a[i][j]=(i==j);
    }
    Fast_Matrax operator * (const Fast_Matrax &B)const
    {
        Fast_Matrax C;
        for(int i=0;i<N;i++)
            for(int k=0;k<N;k++)
                for(int j=0;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&1)res=res*A;
            A=A*A;
            p>>=1;
        }
        return res;
    }
}ans,tmp,x;
int main()
{
    while(~scanf("%lld%lld%d",&f1,&f2,&n))
    {
        x.a[0][0]=f2;x.a[0][1]=f1;x.a[0][2]=1,x.a[0][3]=0;
        if(n==1)printf("%lld\n",f1);
        else if(n==2)printf("%lld\n",f2);
        else
        {
            tmp.a[0][0]=1;tmp.a[0][1]=1;tmp.a[0][2]=0;tmp.a[0][3]=0;
            tmp.a[1][0]=1;tmp.a[1][1]=0;tmp.a[1][2]=0;tmp.a[1][3]=0;
            tmp.a[2][0]=0;tmp.a[2][1]=0;tmp.a[2][2]=0;tmp.a[2][3]=-1;
            tmp.a[3][0]=1;tmp.a[3][1]=0;tmp.a[3][2]=1;tmp.a[3][3]=0;
            ans=x*(tmp^(n-2));
            printf("%lld\n",ans.a[0][0]);
        }
    }
    return 0;
}

 



转载于:https://www.cnblogs.com/jianrenfang/p/6512463.html


http://www.niftyadmin.cn/n/3781837.html

相关文章

爱上MVC~ajax调用分部视图session超时页面跳转问题

回到目录 这个问题出现了很多年了&#xff0c;都没有解决&#xff0c;问题是这样的&#xff0c;有一个需要授权才可以访问的分部视图&#xff0c;在一个view中使用ajax的方法去调用它&#xff0c;然后更新页面的局部DIV&#xff0c;这时&#xff0c;如果你长时间不操作&#xf…

Java类加载器和双亲委派机制

前言 之前详细介绍了Java类的整个加载过程&#xff08;类加载机制详解&#xff09;。虽然&#xff0c;篇幅较长&#xff0c;但是也不要被内容吓到了&#xff0c;其实每个阶段都可以用一句话来概括。 1&#xff09;加载&#xff1a;查找并加载类的二进制字节流数据。 2&#…

H3C常用命令详解

H3C常用命令详解 作者&#xff1a;尹正杰 版权声明&#xff1a;原创作品&#xff0c;谢绝转载&#xff01;否则将追究法律责任。 1.关闭后台日志输出 <yinzhengjie>sys [yinzhengjie]undo info-center enable 2.查看设备IOS版本信息&#xff0c;设备启动时间&#xff0c…

Centos7中mysql安装

一、安装YUM Repo 1、由于CentOS 的yum源中没有mysql&#xff0c;需要到mysql的官网下载yum repo配置文件。 下载命令&#xff1a; wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm 2、然后进行repo的安装&#xff1a; rpm -ivh mysql57-communi…

收集的网站

响应式设计&#xff1a; http://wf.uisdc.com/cn/ UI相关: http://www.uisdc.com/  优设 http://www.xueui.cn/ http://www.xueui.cn/design-theory/learn-ui-1.html  感觉UI也很有意思&#xff0c;慢慢学习 http://www.sketchcn.com/ http://www.cutterman.cn/zh   一款…

输入页 离开页面前弹出框

离开页面确认主要是利用了onbeforeunload事件&#xff0c;存 在着兼容问题 当该事件声明为 &#xff1a; Java代码 <body onbeforeunload "return pageBeforeunload(event);" > <script type "text/javascript" > function pageBeforeunl…

SpringBoot拦截器注入配置文件的配置参数为null的解决方案

在注册拦截器&#xff0c;即继承WebMvcConfigurerAdapter的类中&#xff0c;普通拦截器的注册方法为&#xff1a; Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**");supe…

csdn积分获取攻略

下载积分攻略&#xff1a;1. 个人设置里进行手机绑定CSDN账户 奖励50分 &#xff08;右上角设置-账户安全-手机绑定&#xff09;2. 完成任务送若干分积分 http://task.csdn.net/3. 上传有效资源获取积分&#xff08;上传非法&#xff0c;广告资源用户&#xff0c;将被扣除…