CSU 1233: 病毒的复制 矩阵快速幂
来源:互联网 发布:淘宝店铺处罚规则 编辑:程序博客网 时间:2024/05/08 08:49
CSU 1233: 病毒的复制 矩阵快速幂
Description
Staginner玩完《使命召唤8》后深深地感受到了战争的震撼,没想到在梦中自己也深入到了战场之中干起了为盟军培养病毒的活。
Staginner发明了两种可以相互转化的R、S病毒,对于每个R病毒,每秒钟可以通过自身的复制、变异转化为a1个R病毒和a2个S病毒,而对于每个S病毒,每秒钟可以通过自身的复制、变异转化为b1个R病毒和b2个S病毒。
在初始时刻,培养基里面有a0个R病毒和b0个S病毒,Staginner想知道,若病毒按上述方式进行增殖,在t秒后培养基中一共有多少个病毒呢?
Input
输入包含若干组数据,每组数据占一行,依次为7个不大于10^9的整数a0、b0、a1、a2、b1、b2、t。
数据组数不超过100组,读入以EOF结束。
Output
对于每组数据,用一行输出一个整数,表示t秒后培养基中R、S病毒的总数。由于结果可能很大,你只需要输出结果模1000003的值即可。
Sample Input
1 1 1 2 2 1 0 1 1 1 2 2 1 11 1 1 2 2 1 2
Sample Output
2618
Hint
Source
CSU Monthly 2012 Jan.思路: 矩阵快速幂
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <map>#include <algorithm>#include <ctime>#include <vector>#include <iomanip>using namespace std;long long int a0,b0,a1,b1,a2,b2,tmp1,tmp2,t;const long long int Mod = 1000003;long long int resa = 0,resb = 0;struct Maxtrix{ long long int A[2][2];};Maxtrix Mutiply(Maxtrix a,Maxtrix b){ Maxtrix tmp; memset(tmp.A,0,sizeof(tmp.A)); for(int i = 0 ; i < 2 ; i++) { for(int j = 0 ; j < 2 ; j++) { long long int temp = 0; for(int k = 0 ; k < 2 ; k++) { temp += (a.A[i][k] * b.A[k][j]) % Mod; temp %= Mod; } tmp.A[i][j] = temp % Mod; } } return tmp;}Maxtrix fastpow(Maxtrix x,long long int n){ Maxtrix res; memset(res.A,0,sizeof(res.A)); for(int i = 0 ; i < 2 ; i++) res.A[i][i] = 1; while(n > 0) { if(n&1) res = Mutiply(x,res); x = Mutiply(x,x); n>>=1; } return res;}int main(){ while(scanf("%lld%lld%lld%lld%lld%lld%lld",&a0,&b0,&a1,&a2,&b1,&b2,&t) != EOF) { a0 %= Mod; b0 %= Mod; a1 %= Mod; b1 %= Mod; a2 %= Mod; b2 %= Mod; Maxtrix bb; bb.A[0][0] = a1; bb.A[0][1] = b1; bb.A[1][0] = a2; bb.A[1][1] = b2; bb = fastpow(bb,t); long long int result = ((((a0 * bb.A[0][0]) % Mod) +( (b0 * bb.A[0][1]) % Mod)) % Mod + (((a0 * bb.A[1][0]) %Mod) +( (b0 * bb.A[1][1]) % Mod)% Mod)) % Mod; printf("%lld\n",result); } return 0;}
阅读全文
1 0
- CSU 1233: 病毒的复制 矩阵快速幂
- CSU 1658 IQ of XUEXX’s descendants 矩阵快速幂
- 文章标题 CSU 1831: Found(矩阵快速幂)
- 病毒 CSU
- CSU 1556 快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- 矩阵的快速幂
- CSU 1120 病毒
- CSU 1120 病毒
- CSU 1120 病毒
- 矩阵的乘法和矩阵快速幂
- 博弈——Good Luck in CET-4 Everybody!
- 详解spring 每个jar的作用
- UVa 12161 Ironman Race in Treeland(树分治)
- Leetcode--Two Sum
- lwip TCP client & FreeRTOS 打开TCP 的 保活机制 LWIP_TCP_KEEPALIVE==1
- CSU 1233: 病毒的复制 矩阵快速幂
- meanshift追踪手动选框(python-opencv)
- stl之双端队列deque
- hdu-6092-Rikka with Subset(思维)
- 散列查找
- CSU 1092: Barricade (dijkstra+heap)
- 如何正确地写出单例模式
- 图文混排
- CodeForces