[fzu1692][矩阵乘法]Key problem
2018-02-27 15:00
225 查看
Problem 1692 Key problem
Accept: 214 Submit: 906
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 ( L*A(i+n-1)%n+R*A(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
发现转移矩阵是循环同构的,所以我们只要求第一行,然后n^2递推即可。
这题稍微注意一下,一开始就要去%mod,不然就gg了。(像我)
Accept: 214 Submit: 906
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 ( L*A(i+n-1)%n+R*A(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
sol:
和之前写过的某题很像,随便矩乘一下。然后你T飞了。因为极限数据下是T*n^3*logm的。这个T不知道多少,反正会T。发现转移矩阵是循环同构的,所以我们只要求第一行,然后n^2递推即可。
这题稍微注意一下,一开始就要去%mod,不然就gg了。(像我)
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> using namespace std; typedef long long ll; typedef double s64; int n,m,L,R,pyz; inline int read() { char c; int res,flag=0; while((c=getchar())>'9'||c<'0') if(c=='-')flag=1; res=c-'0'; while((c=getchar())>='0'&&c<='9') res=(res<<3)+(res<<1)+c-'0'; return flag?-res:res; } const int N=110; int a ,b ,tmp ; inline void simplex(int a ) { for(int i=2;i<=n;++i) for(int j=1;j<=n;++j) b[i][j]=b[i-1][j-1?j-1:n]; memset(tmp,0,sizeof(tmp)); for(int j=1;j<=n;++j) for(int k=1;k<=n;++k) tmp[j]=(tmp[j]+(ll)a[1][k]*b[k][j]%pyz)%pyz; for(int j=1;j<=n;++j) a[1][j]=tmp[j]; for(int i=2;i<=n;++i) for(int j=1;j<=n;++j) a[i][j]=a[i-1][j-1?j-1:n]; } inline void ksm(int t) { while(t) { if(t&1) simplex(a); simplex(b); t>>=1; } } inline void solve() { n=read(); m=read(); L=read(); R=read(); pyz=read(); for(int i=1;i<=n;++i) a[1][i]=read()%pyz,b[1][i]=0; b[1] =L;b[1][1]=1;b[1][2]=R; ksm(m); for(int i=1;i<n;++i) printf("%d ",a[1][i]); printf("%d",a[1] ); printf("\n"); } int main() { // freopen("1692.in","r",stdin); // freopen(".out","w",stdout); int T=read(); while(T--) solve(); }
相关文章推荐
- fzu 1692 Key problem(循环同构矩阵o(n^2)优化乘法)
- FZU - 1692 Key problem 矩阵快速幂
- Fzoj 1692 Problem 1692 Key problem [特殊矩阵的n^2复杂度求矩阵乘法]
- FZU 1692 Key problem (构造矩阵)
- fzu 1692 Key problem 循环矩阵
- FZU 1692 Key problem
- fzu 1692(矩阵快速幂)
- FZU 1692 Key problem
- 解题报告:FZU1692 Key problem 循环矩阵快速幂
- HDU 2276 & FZU 1692 (矩阵快速幂+循环同构优化)
- FZU 1692 Key problem(循环矩阵)
- FZU Problem 1692 Key problem(循环矩阵)
- fzu 1683 纪念SlingShot(矩阵乘法)
- fzu 1683 矩阵乘法
- poj3233Matrix Power Series(矩阵乘法)
- 向MapReduce转换:通过部分成绩计算矩阵乘法
- C++ 实现矩阵乘法
- HDU2842 矩阵乘法
- CUDA,day-9,大规模矩阵乘法
- POJ 3318 Matrix Multiplication(矩阵乘法)