您的位置:首页 > 其它

hdu 5084(矩阵操作)

2016-07-10 15:31 363 查看

HeHe

Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 350 Accepted Submission(s): 148


[align=left]Problem Description[/align]

M=⎛⎝⎜⎜⎜⎜⎜⎜⎜⎜⎜tn−1tn−2tn−3⋮t1t0tntn−1tn−2⋮t2t1tn+1tntn−1⋮t3t2⋯⋯⋯⋱⋯⋯t2∗n−3t2∗n−4t2∗n−5⋮tn−1tn−2t2∗n−2t2∗n−3t2∗n−4⋮tntn−1⎞⎠⎟⎟⎟⎟⎟⎟⎟⎟⎟

You are expected to write a program to point out some elements of M∗M.

[align=left]Input[/align]
Multi test cases (about 100), every case occupies two lines.
The first line contains an integer n.
Then second line contain 2*n-1 integers t0,t1,t2,t3,…,t2∗n−4,t2∗n−3,t2∗n−2 separated by exact one space.
The third line contains an integer m, indicates the number of query.
Next m lines will give queries
r0r1r2⋮rm−1c0c1c2⋮cm−1
For r0,c0 the program will query the element of M∗M which locates in the rth0 row, cth0 column. For ri,ci(0<i<m), assume that the answer of i−1th query is ANS, the program will query the element of M∗M which locates in ((ri+ANS)%n)th row, ((ci+ANS)%n)th column.
Please process to the end of file.
[Technical Specification]
1≤n≤1000
0≤ti≤100
0≤ri,ci≤n−1
1≤m≤100000

[align=left]Output[/align]
For each case,output the sum of the answer of each query.

[align=left]Sample Input[/align]

3
1 2 3 1 2
2
0 0
1 2
4
10 5 7 2 10 5 7
3
1 2
3 0
2 1
2
1 2 3
4
0 0
0 1
1 0
1 1

[align=left]Sample Output[/align]

23
348
22

Hint

$\quad\ \text{For the first case }M = \begin{pmatrix}
3 & 1 & 2\\
2 & 3 & 1\\
1 & 2 & 3
\end{pmatrix}$

$\text{For the second case }M = \begin{pmatrix}
2 & 10 & 5 & 7\\
7 & 2 & 10 & 5\\
5 & 7 & 2 & 10\\
10 & 5 & 7 & 2
\end{pmatrix}$

[align=left]Source[/align]
BestCoder Round #15

这题很卡时间,所以我们不能赋值给二维矩阵再去操作,应该直接在 t 数组上面操作,a[i][j] 与 t[n-1+j-i] 一一对应,所以我们求解矩阵上某个值时直接用 t 数组操作好了。还有就是答案会超出整形表示范围,开_int64.

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N = 2005;
int v
;
int n;
int main()
{
while(scanf("%d",&n)!=EOF){
for(int i=0;i<=2*n-2;i++){
scanf("%d",&v[i]);
}
int q;
int temp=0;
long long ans = 0;
scanf("%d",&q);
while(q--){
int r,c;
scanf("%d%d",&r,&c);
r = (r+temp)%n,c = (c+temp)%n;
temp = 0;
for(int i=0;i<n;i++){
temp+= v[n-1+i-r]*v[n-1+c-i];
}
ans += temp;
}
printf("%lld\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: