[原创]FZU 1692 [循环矩阵+矩阵快速幂]【数论】
[原创]FZU 1692 [循环矩阵+矩阵快速幂]【数论】
2016-10-22 16:58:05 Tabris_ 阅读数:316
博客爬取于2020-06-14 22:43:02
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/52893406
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1692
----------------------------------------.
Problem 1692 Key problem
Accept: 197 Submit: 865
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Whenever rxw meets Coral, he requires her to give him the laboratory key. Coral does not want to give him the key, so Coral ask him one question. if rxw can solve the problem, she will give him the key, otherwise do not give him. rxw turns to you for help now,can you help him?
N children form a circle, numbered 0,1,2, … …, n-1,with Clockwise. Initially the ith child has Ai apples. Each round game, the ith child will obtain ( LA(i+n-1)%n+RA(i+1)%n ) apples. After m rounds game, Coral would like to know the number of apples each child has. Because the final figure may be very large, so output the number model M.
Input
The first line of input is an integer T representing the number of test cases to follow. Each case consists of two lines of input: the first line contains five integers n,m,L,R and M . the second line contains n integers A0, A1, A2 … An-1. (0 <= Ai <= 1000,3 <= n <= 100,0 <= L, R <= 1000,1 <= M <= 10 ^ 6,0 <=m < = 10 ^ 9). After m rounds game, output the number model M of apples each child has.
Output
Each case separated by a space. See sample.
Sample Input
1
3 2 3 4 10000
1 2 3
Sample Output
120 133 131
Source
FOJ月赛-2009年3月— Coral
----------------------------------------.
题目大意:就是每个人初始有a[i]个苹果,每一轮能得到左边L倍+右边R倍的苹果,问你M轮之后每个人有多少个苹果.
解题思路:
很明显的矩阵快速幂.构造矩阵非常简单
但是要注意下n≤100 所以n^3会超时,所以要优化一下,
根据矩阵我们能够发现
[1 L 0 0 R]
[R 1 L 0 0]
[0 R 1 L 0]
[0 0 R 1 L]
[L 0 0 R 1]
这是一个很明显的循环矩阵
根据循环矩阵的n次幂还是循环矩阵的这个性质我们每次求解的时候只需要求解一行或一列就可以了,这样的话就能把n^3优化到n^2了
这样就不会超时了
附本题代码
---------------------------------。
1 | //#include <bits/stdc++.h> |