CodeForces - 185A Plant 矩阵快速幂
来源:互联网 发布:网红衣服淘宝店前十名 编辑:程序博客网 时间:2024/05/21 22:38
题目大意:有一个三角形,刚开始是1个up,0个down,1年后,这个三角形变成了3个up,1个down的
之后的每一年,每个三角形都会变成四个,其中三个是相同方向的,1个是相反方向的,问n年后,共有多少个三角形是up的
解题思路:水题啊,看错了题意,以为循环变化指的是其中一年只变up的,然后第二年是所有的三角形都变的那种循环,结果循环是第一年只变up,之后每一年都是所有三角形都在变。。。
变化矩阵,就是(3,1,1,3)是个2*2的矩阵
#include<cstdio>#include<cstring>typedef unsigned long long ll;const int N = 2;const ll mod = 1e9 + 7;struct Matrix{ ll mat[N][N];}A, B, tmp;ll n;Matrix matMul(Matrix x, Matrix y) { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) { tmp.mat[i][j] = 0; for(int k = 0; k < N; k++) tmp.mat[i][j] += (x.mat[i][k] * y.mat[k][j]) % mod; } return tmp;}void solve() { while(n) { if(n & 1) B = matMul(B,A); A = matMul(A,A); n >>= 1; }}void init() { B.mat[0][0] = B.mat[1][1] = 1; A.mat[0][0] = 3; A.mat[0][1] = 1; A.mat[1][0] = 1; A.mat[1][1] = 3;}int main() { init(); scanf("%I64d", &n); if(n == 0) printf("1\n"); else if(n == 1) { printf("3\n"); } else { n -= 1; solve(); printf("%I64d\n", (3 * B.mat[0][0] + B.mat[1][0]) % mod); } return 0;}
0 0
- CodeForces - 185A Plant 矩阵快速幂
- codeforces 185A Plant(矩阵快速幂)
- codeforces 185A. Plant 矩阵快速幂
- CodeForces 185A. Plant (矩阵快速幂)
- codeforces 185A Plant(矩阵快速幂)
- codeforces #185 A Plant(矩阵快速幂+递推)
- CodeForces 185A. Plant(矩阵快速幂)
- CodeForces 185A. Plant(矩阵快速幂) 构造
- codeforces plant 矩阵快速幂
- 【快速幂】 CodeForces 185A Plant
- Codeforces 185A Plant 普通快速幂取模
- Codeforces 185A Plant
- codeforces 185A Plant
- CodeForces 185A - Plant
- CodeForces - 185A Plant
- CodeForces 185A Plant
- Codeforces 185 A Plant
- codeforces 185a(矩阵快速幂)
- linux 下jansson安装和使用
- 流媒体协议介绍(rtp/rtcp/rtsp/rtmp/mms/hls)
- Android夜间模式实现
- web.xml元素详解
- 做个犀利的码农:如何持续培养/更新自己的开发技能
- CodeForces - 185A Plant 矩阵快速幂
- OC 继承
- 最受欢迎的五大bug管理平台
- Hibernate的lazy策略
- Java常见内存溢出(OOM)解决方案
- ireport中unable to resolve class com.google.zxing.qrcode.QRCodeWriter问题解决
- 内存对齐
- java中的锁池和等待池
- 【转】android开发中,可能会导致内存泄露的问题