zoukankan      html  css  js  c++  java
  • HDU 5690 矩阵快速幂

    All X

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 889    Accepted Submission(s): 425


    Problem Description
    F(x,m) 代表一个全是由数字x 组成的m 位数字。请计算,以下式子是否成立:

    F(x,m) mod k  c
     
    Input
    第一行一个整数T ,表示T 组数据。
    每组测试数据占一行,包含四个数字x,m,k,c

    1x9

    1m1010

    0c<k10,000
     
    Output
    对于每组数据,输出两行:
    第一行输出:"Case #i:"。i 代表第i 组测试数据。
    第二行输出“Yes” 或者 “No”,代表四个数字,是否能够满足题目中给的公式。
     
    Sample Input
    3
    1 3 5 2
    1 3 5 1
    3 5 99 69
     
    Sample Output
    Case #1: No
    Case #2: Yes
    Case #3: Yes
    Hint
    对于第一组测试数据:111 mod 5 = 1,公式不成立,所以答案是”No”,而第二组测试数据中满足如上公式,所以答案是 “Yes”。
     
    Source
     
    题意:中文题意
     
    题解:构造矩阵
    10 ,0       xx , xx      10*xx+1*xx ,  xx
     1  ,1  *   0   ,0 =     0                ,   0         
     
    m[0][0]为结果
     
    在矩阵构造方面 还是好菜的 之前构造的 一直wa
    常系数矩阵中不能有未知数!!!
    matrix_quick(x,m-1); m-1次幂
     
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<queue>
     5 #include<stack>
     6 #include<map>
     7 #define mod 10000
     8 #define ll __int64
     9 using namespace std;
    10 struct matrix
    11 {
    12    ll m[5][5];
    13 } ans,exm;
    14 ll x,m,k,c;
    15 struct matrix matrix_mulit(struct matrix aa,struct matrix bb)
    16 {
    17     struct matrix there;
    18     for(int i=0;i<2;i++)
    19     {
    20         for(int j=0;j<2;j++)
    21         {
    22             there.m[i][j]=0;
    23             for(int u=0;u<2;u++)
    24             there.m[i][j]=(there.m[i][j]+aa.m[i][u]*bb.m[u][j]%k)%k;
    25         }
    26     }
    27     return there;
    28 }
    29 ll matrix_quick(ll xx,ll gg)
    30 {
    31      exm.m[0][0]=10;
    32      exm.m[0][1]=0;
    33      exm.m[1][0]=1;
    34      exm.m[1][1]=1;
    35      ans.m[0][0]=xx;
    36      ans.m[1][1]=0;  
    37      ans.m[0][1]=xx;
    38      ans.m[1][0]=0;
    39      while(gg)
    40      {
    41          if(gg&1)  
    42         ans=matrix_mulit(ans,exm);        
    43         exm = matrix_mulit(exm, exm);
    44         gg >>= 1;
    45     }
    46      return ans.m[0][0];
    47 } 
    48 ll n; 
    49 int main()
    50 {
    51         while(scanf("%I64d",&n)!=EOF)
    52        {
    53         for(ll i=1;i<=n;i++)
    54         {
    55             scanf("%I64d %I64d %I64d %I64d",&x,&m,&k,&c);
    56             printf("Case #%d:
    ",i);
    57             ll ggg=matrix_quick(x,m-1);
    58             if(ggg==c)
    59             printf("Yes
    ");
    60             else  
    61             printf("No
    ");  
    62         }
    63     }
    64     return 0;
    65 }
     
  • 相关阅读:
    maven本地添加Oracle包
    tomcat启动时检测到循环继承而栈溢出的问题:Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/test] due to a StackOverflowError. Possible root causes include
    C# LINQ list遍历并组装返回新查询
    windows server 2016下360wifi安装
    Python获取本机多IP并指定出口IP
    python读取excel和读取excel图片总结
    windows2012/2016/2019 iis自带ftp被动端口修改
    Flutter IOS build成功,archive失败
    centos常用操作
    Git相关操作
  • 原文地址:https://www.cnblogs.com/hsd-/p/5521162.html
Copyright © 2011-2022 走看看