【Openjudge 9277 Logs Stacking堆木头】 题解

题目链接:http://noi.openjudge.cn/ch0206/9277/
...

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
struct Matrix{
	long long m[3][3];
}A,E,ans;
long long n,k, mod = 1e5;
Matrix mul(Matrix A,Matrix B)
{
	Matrix C;
	for(int i = 1; i <= 2; i++)
		for(int j = 1; j <= 2; j++)
		{
			C.m[i][j] = 0;
			for(int k = 1; k <= 2; k++)
				C.m[i][j] = (C.m[i][j]+(A.m[i][k]*B.m[k][j]))%mod;	
		}
	return C;
}
Matrix fast(Matrix A, long long k)
{
	Matrix S = E;
	while(k)
	{
		if(k&1) S = mul(S,A);
		A = mul(A,A);
		k = k>>1;
	}
	return S;
}
int main()
{
	E.m[2][2] = 1;
	E.m[1][1] = 1;
	A.m[1][1] = 1;
	A.m[1][2] = 1;
	A.m[2][1] = 1;
	scanf("%d",&n);
   for(int i = 1; i <= n; i++)
   {
      scanf("%lld",&k);
      ans = fast(A,2*k-1);
		printf("%lld
",(ans.m[2][1])%mod);
   }
	return 0;
}

原文地址:https://www.cnblogs.com/MisakaAzusa/p/9325268.html