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; }
相关文章推荐
- Spring配置文件中<context:annotation-config/>
- QT中全屏显示子窗口的方法
- hdu 5185(dp)
- php读取json时无数据(为空)的解决方法
- [置顶] Linux Malloc分析-从用户空间到内核空间【转】
- Qt_Android_书
- 一道关于股票买卖的算法编程题
- V6+2C6678调试之小FPGA--S3
- hdu 3374 next表,最大最小表示法模板
- Python添加默认模块搜索包路径
- 对Java异常分析的一些见解
- malloc()之后,内核发生了什么?【转】
- 汇编语言实现一个简单的十六进制转储使用工具
- PopupWindow的使用
- Avalanche测试仪基本使用(二)
- 动态修改QGridLayout
- 【搜商】程序员应该必备的10个搜索技巧 ,你知道几个?
- 前景检测算法(十一)--基于LBP纹理
- Guacamole——1.实现和架构
- redis 主从搭建