hdu 5084(矩阵操作)
HeHe
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 350 Accepted Submission(s): 148
You are expected to write a program to point out some elements of M∗M.
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
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
348
22
$\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}$
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N = ;
int v[N];
int n;
int main()
{
while(scanf("%d",&n)!=EOF){
for(int i=;i<=*n-;i++){
scanf("%d",&v[i]);
}
int q;
int temp=;
long long ans = ;
scanf("%d",&q);
while(q--){
int r,c;
scanf("%d%d",&r,&c);
r = (r+temp)%n,c = (c+temp)%n;
temp = ;
for(int i=;i<n;i++){
temp+= v[n-+i-r]*v[n-+c-i];
}
ans += temp;
}
printf("%lld\n",ans);
}
return ;
}
hdu 5084(矩阵操作)的更多相关文章
- Linear regression with one variable算法实例讲解(绘制图像,cost_Function ,Gradient Desent, 拟合曲线, 轮廓图绘制)_矩阵操作
%测试数据 'ex1data1.txt', 第一列为 population of City in 10,000s, 第二列为 Profit in $10,000s 1 6.1101,17.592 5. ...
- iOS开发UI篇—Quartz2D使用(矩阵操作)
iOS开发UI篇—Quartz2D使用(矩阵操作) 一.关于矩阵操作 1.画一个四边形 通过设置两个端点(长和宽)来完成一个四边形的绘制. 代码: - (void)drawRect:(CGRect)r ...
- 【iOS】Quartz2D矩阵操作
前面画基本图形时,画四边形是由几条直线拼接成的,现在有更简便的方法. 一.关于矩阵操作 1.画一个四边形 通过设置两个端点(长和宽)来完成一个四边形的绘制. 代码: - (void)drawRect: ...
- MATLAB命令大全和矩阵操作大全
转载自: http://blog.csdn.net/dengjianqiang2011/article/details/8753807 MATLAB矩阵操作大全 一.矩阵的表示在MATLAB中创建矩阵 ...
- Matlab、R向量与矩阵操作 z
已有 1849 次阅读 2012-8-2 15:15 |系统分类:科研笔记|关键词:矩阵 480 window border center Matlab.R向量与矩阵操作 描 述 Matla ...
- Python中的矩阵操作
Numpy 通过观察Python的自有数据类型,我们可以发现Python原生并不提供多维数组的操作,那么为了处理矩阵,就需要使用第三方提供的相关的包. NumPy 是一个非常优秀的提供矩阵操作的包.N ...
- poj3735—Training little cats(特殊操作转化为矩阵操作)
题目链接:http://poj.org/problem?id=3735 题目意思: 调教猫咪:有n只饥渴的猫咪,现有一组羞耻连续操作,由k个操作组成,全部选自: 1. g i 给第i只猫咪一颗花生 2 ...
- Matlab、R向量与矩阵操作
Matlab.R向量与矩阵操作 描 述 Matlab R 1 建立行向量v=[1 2 3 4] v=[1 2 3 4] v<-c(1,2,3,4)或v<-scan(),然后输入 ...
- Leetcode 566. Reshape the Matrix 矩阵变形(数组,模拟,矩阵操作)
Leetcode 566. Reshape the Matrix 矩阵变形(数组,模拟,矩阵操作) 题目描述 在MATLAB中,reshape是一个非常有用的函数,它可以将矩阵变为另一种形状且保持数据 ...
随机推荐
- Hyper-V中的Linux无法配置网络地址的解决办法
一周碰到2次在Hyper-V 2012中安装了Linux,也安装了IC 3.4.但是却无法配置IP地址的问题.因此造成很多不便,因此找机会把这个原因和解决办法进行了尝试. 这过程中感谢同事的提示,让我 ...
- JavaWeb项目中使用ajax上传文件
1.jsp $("#cxsc").click(function(){ var bankId = $("#bankId").val(); var formdata ...
- Oracle 遇到的问题:IMP-00041: 警告: 创建的对象带有编译警告解决办法
出现IMP-00041: 警告: 创建的对象带有编译警告:以后再做数据迁移的时候需要额外注意,尤其用户中有视图或者触发器对象的时候.用户的环境是这样的,在库里有三个oracle的用户,其中一个用户中有 ...
- CS局域网射击
2/3D游戏:3D 辅助插件:角色控制器 游戏制作难度系数:中级 用到的其他工具:network 一.解决由于子弹射击速度过快而无法打到物体的问题 //方法一: ; Vector3 originalP ...
- 源码分析(一) HashMap 源码分析|JDK8
HashMap是一个普遍应用于各大JAVA平台的最最最常用的数据结构.<K,V>的存储形式使HashMap备受广大java程序员的喜欢.JDK8中HashMap发生了很大的变化,例如:之前 ...
- Leetcode 671.二叉树中第二小的节点
二叉树中第二小的节点 给定一个非空特殊的二叉树,每个节点都是正数,并且每个节点的子节点数量只能为 2 或 0.如果一个节点有两个子节点的话,那么这个节点的值不大于它的子节点的值. 给出这样的一个二叉树 ...
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
- 深入理解CSS中的margin
1.css margin可以改变容器的尺寸 元素尺寸 可视尺寸--标准盒子模型中盒子的宽度是不包括margin值的,clientWidth 占据尺寸--包括margin的宽度 outWidth不在标准 ...
- Thread suspend()挂起resume()恢复
import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.Actio ...
- Win10 Ubuntu18.04 编译安装 nignx
nginx 下载页 http://nginx.org/en/download.html wget http://nginx.org/download/nginx-1.14.0.tar.gz //安装依 ...