FZU Problem 1692 Key problem(迴圈矩陣)
迴圈矩陣,這裡有講解:http://wenku.baidu.com/link?url=zcJ-sxrj0QDqzz8xCnHTnB7gxjoNRyOZzS4_4ZA22c8Bs9inYn6vVkqTVr_w-riLa8oRnYA9SRcCZ9f4UciCUNGeNAG4dCGclYRPS18YLGa
推出第一層下面根據性質就可以得到。
Problem 1692 Key problem
Accept: 144 Submit: 663
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#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define pi acos(-1.0)
#define LL __int64
using namespace std;
const int maxn = 110;
LL a[maxn], b[maxn], f[maxn];
LL mod, n;
void mul(LL a[], LL b[])
{
LL c[maxn];
memset(c, 0, sizeof(c));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) c[i] = (a[j]*b[(i-j+n)%n]+c[i])%mod;
memcpy(a, c, sizeof(c));
}
void pow_mod(LL a[], LL b)
{
LL c[maxn];
memset(c, 0, sizeof(c));
c[0] = 1LL;
while(b)
{
if(b&1) mul(c, a);
mul(a, a);
b >>= 1;
}
memcpy(a, c, sizeof(c));
}
int main()
{
int T;
cin>>T;
LL m, l, r;
while(T--)
{
cin>>n>>m>>l>>r>>mod;
for(int i = 0;i < n;i++) cin>>a[i];
memset(f, 0, sizeof(f));
f[0] = 1; f[1] = r; f[n-1]=l;
pow_mod(f, m);
LL ans[maxn];
for(int i = 0; i < n; i++)
{
ans[i] = 0;
for(int j = 0;j < n;j++)
ans[i] = (ans[i]+a[j]*f[(i-j+n)%n])%mod;
}
cout<<ans[0];
for(int i = 1; i < n; i++) cout<<" "<<ans[i];
cout<<endl;
}
return 0;
}
相關文章
- HDU 4291 A Short problem(矩陣快速冪+迴圈節)矩陣
- HDU 2256Problem of Precision(矩陣快速冪)矩陣
- Problem_2 Majority Problem
- LightOJ 1070 Algebraic Problem:矩陣快速冪 + 數學推導AI矩陣
- Mathematical Problem
- 最大子陣列問題(Maximum subarray problem)陣列
- ACM A problem is easyACM
- Database Transaction ProblemDatabase
- Yet Another Problem
- Fixed "There was a problem with the editor 'vi'"
- STL iterator delete problemdelete
- E. Not a Nim Problem
- 陣列迴圈陣列
- HDU 1792 A New Change Problem
- Joe Harris is a real problem with this team
- The Door Problem 並查集並查集
- 3339: Rmq ProblemMQ
- ORB problem determinationORB
- Nanami and the Constructive ProblemNaNStruct
- DAO迴圈矩陣互助公排系統開發模式功能矩陣模式
- 陣列迴圈移位陣列
- Assignment Problem的若干思考
- Problem 4:替換空格(字串)字串
- [Algorithm] 1. A+B ProblemGo
- A - Yet Another Two Integers Problem ACMACM
- NC17383 A Simple Problem with Integers
- HDU5293 : Tree chain problemAI
- 【poj3468】A Simple Problem with Integers
- LintCode-A+B Problem
- google api , the problem of null refresh tokenGoAPINull
- Training - Problem and Change ManagementAI
- "toy problem"怎麼翻譯
- Nanami and the House Protecting ProblemNaN
- QOJ6836 A Plus B Problem
- P1865 A % B Problem
- 解決git SSL certificate problemGit
- ECE 498/598 Associative Recall Problem
- 陣列迴圈輸出陣列