• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

HDU 2256 Problem of Precision

题意:

思路:

打表出前几项的结果:9,97,969,9601,95049,940897
 
用x表示(sqrt(2.0)+sqrt(3.0))^2
 
先求出  x  =  5+2*sqrt(6.0)      ->      (5*2-1)%1024=9
 
       x^2 =  49+20*sqrt(6.0)    ->      (49*2-1)%1024=97
 
       x^3 =  485+198*sqrt(6.0)  ->      (485*2-1)%1024=969
 
       ....
 
 现在我们就能找出规律了。   49 = 5*5+2*2*6  =  5*5+2*12       20 = 5*2 + 2*5
 
                           485 = 49*5+20*2*6  =  49*5+20*12   198 = 49*2 + 20*5
 
(如果不确定你可以在多做一位就知道了) 
 
| 5 12 | * | 5 | = | 49 | * | 5 12 | = | 485 | ... 
| 2 5  |   | 2 |   | 20 |   | 2 5  |   | 198 |

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256

 

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <string>
 5 #include <algorithm>
 6 #include <iostream>
 7 using namespace std;
 8 const int N=3;
 9 const int mod=1024;
10 
11 typedef struct In{
12     int m[N][N];
13 }Matrix;
14 Matrix init,unit,F;
15 int n;
16 
17 void Init(){
18     for(int i=1;i<N;i++)
19         for(int j=1;j<N;j++)
20             unit.m[i][j]=(i==j);
21     init.m[1][1]=5;
22     init.m[1][2]=12;
23     init.m[2][1]=2;
24     init.m[2][2]=5;
25     F.m[1][1]=5;
26     F.m[2][1]=2;
27 }
28 
29 Matrix Mul(Matrix a,Matrix b){
30     Matrix c;
31     for(int i=1;i<N;i++)
32         for(int j=1;j<N;j++){
33             c.m[i][j]=0;
34             for(int k=1;k<N;k++){
35                 c.m[i][j]+=a.m[i][k]*b.m[k][j];
36                 c.m[i][j]%=mod;
37             }
38         }
39     return c;
40 }
41 
42 Matrix Pow(Matrix a,Matrix b){
43     n--;
44     while(n){
45         if(n&1) b=Mul(a,b);
46         a=Mul(a,a);
47         n>>=1;
48     }
49     return b;
50 }
51 
52 int main(){
53     
54 //    freopen("data.in","r",stdin);
55 //    freopen("data.out","w",stdout);
56     
57     int t;
58     scanf("%d",&t);
59     while(t--){
60         scanf("%d",&n);
61         if(n==1){
62             puts("9");
63             continue;
64         }
65         Init();
66         Matrix x=Pow(init,unit);
67         x=Mul(x,F);
68         printf("%d\n",(x.m[1][1]*2-1)%mod);
69     }
70     return 0;
71 }

 

posted @ 2012-05-04 08:01  Hug_Sea  阅读(177)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3