zoukankan      html  css  js  c++  java
  • HDU 4686 Arc of Dream

    Arc of Dream

    Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
    Total Submission(s): 3947    Accepted Submission(s): 1220


    Problem Description
    An Arc of Dream is a curve defined by following function:

    where
    a0 = A0
    ai = ai-1*AX+AY
    b0 = B0
    bi = bi-1*BX+BY
    What is the value of AoD(N) modulo 1,000,000,007?
     
    Input
    There are multiple test cases. Process to the End of File.
    Each test case contains 7 nonnegative integers as follows:
    N
    A0 AX AY
    B0 BX BY
    N is no more than 1018, and all the other integers are no more than 2×109.
     
    Output
    For each test case, output AoD(N) modulo 1,000,000,007.
     
    Sample Input
    1 1 2 3 4 5 6 2 1 2 3 4 5 6 3 1 2 3 4 5 6
     
    Sample Output
    4 134 1902
     
    Author
    Zejun Wu (watashi)
    Source
     
    Recommend
    zhuyuanchen520
     
     
    由已知条件,可以得到下面矩阵式子
     
    进一步变换得到
    n>=1,
     
    这样,就可以使用矩阵快速幂运算进行求解。
     
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <map>
     4 #include <vector>
     5 #include <functional>
     6 #include <string>
     7 #include <cstring>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 #include <cstdio>
    12 using namespace std;
    13 #define IOS ios_base::sync_with_stdio(false)]
    14 typedef long long LL;
    15 const int INF=0x3f3f3f3f;
    16 
    17 const int maxn=6;
    18 const int modnum=1000000007;
    19 typedef struct matrix{
    20     int v[maxn][maxn];
    21     void init(){memset(v,0,sizeof(v));}
    22 }M;
    23 M mul_mod(const M &a,const M &b,int L,int m,int n)
    24 {
    25     M c; c.init();
    26     for(int i=0;i<L;i++){
    27         for(int j=0;j<n;j++){
    28             for(int k=0;k<m;k++)//注意j,k范围
    29                 c.v[i][j]=(c.v[i][j]+int((LL)a.v[i][k]*b.v[k][j]%modnum))%modnum;
    30         }
    31     }
    32     return c;
    33 }
    34 M power(M x,int L,LL p)
    35 {
    36     M tmp; tmp.init();
    37     for(int i=0;i<L;i++)
    38         tmp.v[i][i]=1;
    39     while(p){
    40         if(p&1) tmp=mul_mod(x,tmp,L,L,L);
    41         x=mul_mod(x,x,L,L,L);
    42         p>>=1;
    43     }
    44     return tmp;
    45 }
    46 int main()
    47 {
    48     LL n;
    49     int a0,ax,ay,b0,bx,by;
    50     M a,b;
    51     while(scanf("%lld",&n)!=EOF){
    52         scanf("%d%d%d%d%d%d",&a0,&ax,&ay,&b0,&bx,&by);
    53         if(n==0){printf("0
    "); continue;}
    54         a.init();
    55         a.v[0][0]=1;
    56         a.v[0][1]=a.v[1][1]=int((LL)ax*bx%modnum);
    57         a.v[0][2]=a.v[1][2]=int((LL)ax*by%modnum);
    58         a.v[0][3]=a.v[1][3]=int((LL)ay*bx%modnum);
    59         a.v[0][4]=a.v[1][4]=int((LL)ay*by%modnum);
    60         a.v[2][2]=ax%modnum;
    61         a.v[2][4]=ay%modnum;
    62         a.v[3][3]=bx%modnum;
    63         a.v[3][4]=by%modnum;
    64         a.v[4][4]=1;
    65         b.init();
    66         b.v[0][0]=int((LL)a0*b0%modnum);
    67         b.v[1][0]=int((LL)a0*b0%modnum);
    68         b.v[2][0]=a0%modnum;
    69         b.v[3][0]=b0%modnum;
    70         b.v[4][0]=1;
    71         a=power(a,5,n-1);
    72         a=mul_mod(a,b,5,5,1);
    73         printf("%d
    ",a.v[0][0]);
    74     }
    75 }
  • 相关阅读:
    史上最完整的Android开发工具集合(转)
    史上最完整的Android开发工具集合(转)
    JSP取得绝对路径
    ExecutorService 的理解与使用
    JAVA多线程实现的三种方式 ()
    高并发策略实例分析
    spring framework体系结构及内部各模块jar之间的maven依赖关系
    js 去掉下划线,后首个字母变大写
    Cron表达式
    eclipse中怎么找项目部署的路径和找编译后的class路径
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5692577.html
Copyright © 2011-2022 走看看