Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:感觉写的很清晰

Posted by ACM_herongwei at 2014-10-11 12:27:43 on Problem 3233
In Reply To:感觉写的很清晰 Posted by:shenkuangji at 2012-07-04 20:58:00
> 解法二 700K	141MS
> #include<cstdio>
> #include<iostream>
> using namespace std;
> int k,n,base;
> struct matrix
> {
>     int n;
>     int m[33][33];
>     void clear()
>     {
>          for (int i=1;i<=n;i++)
>              for (int j=1;j<=n;j++)
>                  m[i][j]=0;     
>     }
>     void in(int t)
>     {
>          n=t;
>          for (int i=1;i<=n;i++)
>              for (int j=1;j<=n;j++)
>                  scanf("%d",&m[i][j]);     
>     }
>     void out()
>     {
>          for (int i=1;i<=n;i++)
>          {
>              for (int j=1;j<n;j++)
>                  printf("%d ",m[i][j]);
>              printf("%d\n",m[i][n]);    
>          }     
>     }
>     void operator +=(const matrix &b)
>     {
>          for (int i=1;i<=n;i++)
>              for (int j=1;j<=n;j++)
>                  m[i][j]=(m[i][j]+b.m[i][j])%base;     
>     }
> }a,b,f;
> matrix operator *(const matrix &a,const matrix &b)
> {
>     matrix c;
>     c.n=n;
>     c.clear();
>     for (int i=1;i<=n;i++)
>         for (int j=1;j<=n;j++)
>             for (int k=1;k<=n;k++)
>                 c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j])%base;
>     return c;
> }
> int main()
> {
>     scanf("%d%d%d",&n,&k,&base);
>     a.in(n);
>     b=a;
>     f=a;
>     int i;
>     for (i=0;(1<<i)<=k;i++);
>     for (i-=2;i>=0;i--)
>     {
>         f+=b*f;
>         b=b*b;
>         if (((1<<i)&k)>0) b=b*a,f+=b;       
>     }
>     f.out();
>     return 0;   
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator