HDU 2065
来源:互联网 发布:linux上安装jira 编辑:程序博客网 时间:2024/05/25 05:37
HDU 2065
矩阵快速幂,好激动,第一次用矩阵快速幂AC,虽然构建矩阵+写代码用了一个上午·····作为弱菜的我已经很满足了!
也没有什么要讲得,中文题目,构建矩阵,熟练就好。
int start[4]={2,1,1,0};这里没有用到,提醒一下自己而已,一开始n=1时候,有4个串分别为,A,B,C,D;
这个数组记录的就是 { AC同时为偶数的数量,A偶C奇的数量,A奇C偶的数量,AC同为奇数的数量}
#include<iostream>#include<cstring>#include<cmath>#include<map>#include<algorithm>#include<stdio.h>#include<string>using namespace std;#define LL long long#define M 100int start[4]={2,1,1,0};int matrix[4][4]={{2,1,1,0},{1,2,0,1},{1,0,2,1},{0,1,1,2}};class Matrix{public: LL c[4][4]; Matrix(){ for(int i = 0;i < 4;i ++) for(int j = 0;j < 4;j ++) c[i][j] = 0; }void deal(){for(int i = 0;i < 4;i ++) for(int j = 0;j < 4;j ++) c[i][j] = matrix[i][j];}};Matrix mul(const Matrix & t1,const Matrix & t2){ int i,j,k; Matrix t3; for(i = 0;i < 4;i ++) { for(j = 0;j < 4;j ++){ for(k = 0;k < 4;k ++){ t3.c[i][j] = (t3.c[i][j] + t1.c[i][k]*t2.c[k][j])%M; } } } return t3;}Matrix power(long long n){Matrix a,b;b.deal();if(n==1)return b;else if(n%2==1){a=(power(n/2));return mul(mul(a,a),b);}else{a=(power(n/2));return mul(a,a);}}int main(){int t,i,k,l=0;long long n;while(cin>>t&&t){for(k=1;k<=t;k++){cin>>n;cout<<"Case "<<k<<": ";if(n==1){cout<<2<<endl;continue;}Matrix s=power(n-1);cout<<(s.c[0][0]*2+s.c[0][1]+s.c[0][2])%M<<endl;}cout<<endl;}return 0;}
- hdu 2065
- HDU 2065
- hdu 2065
- HDU 2065
- HDU 2065
- hdu 2065
- hdu 2065
- hdu 2065 红色病毒
- hdu 2065 (AC自动机)
- HDU 2065 母函数
- HDU 2065 红色病毒
- HDU 2065 红色病毒
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- OpenStack简介和相关资料
- 文件异地直接复制: scp
- PHP+MYSQL+IIS5.1配置问题集锦
- 搜狐2012.9.15校园招聘会笔试题
- Android Intent Action 大全(转)
- HDU 2065
- ssh服务器启动和客户端常用操作(转)
- 转:s3c2440对nandflash的操作(K9F2G08)
- 蛋疼的主从 MySQL Event
- POJ 2352 Stars
- Android 文件存放路径
- ssh服务器公钥记录文件(转)
- TCP连接的建立过程
- 家庭影院.液晶电视.常见接口介绍