UVA - 10895 Matrix Transpose
来源:互联网 发布:ubuntu kernel devel 编辑:程序博客网 时间:2024/05/23 01:58
[Submit] [Go Back] [Status]
Description
A: Matrix Transpose
A matrix is a rectangular array of elements, most commonly numbers. A matrix with rows and columns is said to be an-by- matrix. For example,is a 4-by-3 matrix of integers.
The individual elements of a matrix are usually given lowercase symbols and are distinguished by subscripts. Theth row andth column of matrix is usually referred to as. For example,. Matrix subscripts are 1-based.
The transpose of a matrix , denoted, is formed by interchanging the rows and columns of. That is, theth element of is theth element of. For example, the transpose of matrix above is:
A matrix is said to be sparse if there are relatively few non-zero elements. As a-by- matrix has number of elements, storing all elements of a large sparse matrix may be inefficient as there would be many zeroes. There are a number of ways to represent sparse matrices, but essentially they are all the same: store only the non-zero elements of the matrix along with their row and column.
You are to write a program to output the transpose of a sparse matrix of integers.
Input
You are given several sparse matrix in a row, each of them described as follows. The first line of the input corresponds to the dimension of the matrix, and (which are the number of rows and columns, respectively, of the matrix). You are then given sets of numbers, which represent the rows of the matrix. Each set consists of two lines which represents a row of the matrix. The first line of a set starts with the number , which is the number of non-zero elements in that row, followed by numbers which correspond to the column indices of the non-zero elements in that row, in ascending order; the second line has integers which are the matrix elements of that row. For example, matrix above would have the following representation:4 33 1 2 31 3 22 2 34 -103 1 2 35 -2 11Note that for a row with all zero elements, the corresponding set would just be one number, `0', in the first line, followed by a blank line.
You may assume:
- the dimension of the sparse matrix would not exceed 10000-by-10000,
- the number of non-zero element would be no more than 1000,
- each element of the matrix would be in the range of -10000 to 10000, and
- each line has no more than 79 characters.
Output
For each input case, the transpose of the given matrix in the same representation.Sample Input
4 33 1 2 31 3 22 2 34 -103 1 2 35 -2 11
Sample Output
3 42 1 41 53 1 2 43 4 -23 1 2 42 -1 11
题意:首先给你n*m的矩阵,然后给出每行的情况。第一个数r代表该行有几个非0的数,位置是哪里,然后给出每个位置的值,求矩阵的倒置
思路:用两个vector,一个记录该列有效值所对应的行,还一个记录该位置的值
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <vector>using namespace std;const int MAXN = 10010;vector<int> row[MAXN];vector<int> val[MAXN];int n, m, arr[MAXN];void print() {printf("%d %d\n", m, n);for (int i = 1; i <= m; i++) {int len = row[i].size();printf("%d", len);for (int j = 0; j < len; j++)printf(" %d", row[i][j]);if (len == 0)printf("\n\n");else {printf("\n%d", val[i][0]);for (int j = 1; j < len; j++)printf(" %d", val[i][j]);printf("\n");}}}int main() {while (scanf("%d%d", &n ,&m) != EOF) {for (int i = 0; i < MAXN; i++) {row[i].clear();val[i].clear();}int r, x;for (int i = 1; i <= n; i++) {scanf("%d", &r);for (int j = 1; j <= r; j++)scanf("%d", &arr[j]);for (int j = 1; j <= r; j++) {scanf("%d", &x);row[arr[j]].push_back(i);val[arr[j]].push_back(x);}}print();}return 0;}
- Uva 10895 - Matrix Transpose
- uva 10895 Matrix Transpose
- UVA 10895 Matrix Transpose
- UVA - 10895 Matrix Transpose
- UVa 10895 Matrix Transpose
- UVa 10895 - Matrix Transpose
- UVA 10895 - Matrix Transpose(STL)
- uva 10895 - Matrix Transpose(STL)
- UVA - 10895Matrix Transpose(vector)
- UVA 10895——Matrix Transpose
- Matrix Transpose
- Inverse transpose matrix
- Sparse Matrix's Transpose
- numpy基础——matrix.transpose() 和 matrix.getA()
- Programming trivia: 4x4 integer matrix transpose in SSE2
- UVA 11019 Matrix Matcher
- Uva 11019 Matrix Matcher
- UVA 11019 Matrix Matcher
- ZOJ-1156
- MyEclipse项目改名
- github常见错误
- 工作点滴:办公椅。
- Java 转换流 简介
- UVA - 10895 Matrix Transpose
- 持续集成工具的选择
- 1001. A+B Format (20)
- 有源滤波器和无源滤波器的区别及原理
- GCD及其扩展GCD详解
- POJ3258 River Hopscotch 二分搜索
- Vawio Sequence
- 【读书笔记】【收获,不止Oracle】嵌套循环表(Nested Loops Join)
- 中国大陆开源镜像站汇总