#include <iostream>
using namespace std; int n, m, q;
struct node {
int v; // 节点权值
int r; // 右侧节点在arr[]中的位置
int d; // 下侧节点在arr[]中的位置
node() {v = r = d = -;} // 初始化
} arr[ * ]; // 利用矩阵行列位置确定在arr[]中的位置
int locate(int x, int y)
{
return x * (m + ) + y;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(); cin >> n >> m >> q; // 输入权值
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
cin >> arr[locate(i, j)].v; // 再次遍历确定节点的右侧和下侧 注意是从0开始!
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
arr[locate(i, j)].r = locate(i, j + );
arr[locate(i, j)].d = locate(i + , j);
}
} // 询问
int x1, y1, x2, y2, h, w;
while (q--) {
cin >> x1 >> y1 >> x2 >> y2 >> h >> w;
// 找到两个子矩阵左上角的左上角的位置
int p1 = , p2 = ;
for (int i = ; i < x1; i++)
p1 = arr[p1].d;
for (int i = ; i < y1; i++)
p1 = arr[p1].r;
for (int i = ; i < x2; i++)
p2 = arr[p2].d;
for (int i = ; i < y2; i++)
p2 = arr[p2].r; // 改变子矩阵边界的d、r
int r1 = p1, r2 = p2;
for (int i = ; i <= h; i++) {
r1 = arr[r1].d;
r2 = arr[r2].d;
swap(arr[r1].r, arr[r2].r);
}
for (int i = ; i <= w; i++) {
r1 = arr[r1].r;
r2 = arr[r2].r;
swap(arr[r1].d, arr[r2].d);
}
r1 = p1;
r2 = p2;
for (int i = ; i <= w; i++) {
r1 = arr[r1].r;
r2 = arr[r2].r;
swap(arr[r1].d, arr[r2].d);
}
for (int i = ; i <= h; i++) {
r1 = arr[r1].d;
r2 = arr[r2].d;
swap(arr[r1].r, arr[r2].r);
}
} // 输出改变后的矩阵
int p = ;
for (int i = ; i <= n; i++) {
bool flag = true;
p = arr[p].d;
int k = p;
for (int j = ; j <= m; j++) {
k = arr[k].r;
if (flag) {
cout << arr[k].v;
flag = false;
}
else cout << ' ' << arr[k].v;
}
cout << endl;
}
return ;
}

5A - Matrix的更多相关文章

  1. angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation

    今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:

  2. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  3. Atitit Data Matrix dm码的原理与特点

    Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...

  4. Android笔记——Matrix

    转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...

  5. 通过Matrix进行二维图形仿射变换

    Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...

  6. [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  7. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  8. [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. [LeetCode] Search a 2D Matrix 搜索一个二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

随机推荐

  1. JS 页面刷新或重载

    一.先来看一个简单的例子:下面以三个页面分别命名为frame.html.top.html.bottom.html为例来具体说明如何做.frame.html 由上(top.html)下(bottom.h ...

  2. POJ 3169 C - Layout

    题意 有n头奶牛从1到n编号,按照编号顺序站成一排,有可能有多头奶牛站在同一个坐标上.一些奶牛互相喜欢,所以他们的距离不能大于某个距离,一些奶牛互相讨厌,所以他们的距离不能小于某个距离,请计算如果可能 ...

  3. Eclipse右击jsp没有运行选项

    maven项目低级错误,没有更新maven资源库.....更新后就运行起来了

  4. 69. Sqrt(x) 求根号再取整

    [抄题]: Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to b ...

  5. 为Vmware里安装的CentOS7.5设置静态IP

    [引言]为测试搭建大数据集群环境,采用在Vmware里安装了几台CentOS7.5的虚拟机,在测试过程中,出现启动虚拟机后,虚拟机的IP地址会变,不方便测试集群,所以需要设置静态IP,在此,记录我的设 ...

  6. MySQL中having与where

    having与where区别: where中不可以用聚合函数(条件字段是未分组中的字段),having中可以用聚合函(条件字段是分组后字段).不过这里也很好理解,SQL语句在执行是先执行select ...

  7. Shiro——认证概述

    认证流程 身份认证流程 首先调用 Subject.login(token) 进行登录,其会自动委托给SecurityManager SecurityManager 负责真正的身份验证逻辑:它会委托给A ...

  8. poj 1611 The Suspects(第一道并查集)

    题意: 有N个学生,编号为0-n-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染, 并且这些人如果还参加了别的社团,他所在的社团照样全部感染,社团个数为m,求感染的人数. 输入: n代表人 ...

  9. SVN常见问题及解决方式(一)

    1.每天早上上班要update SVN,每天下班要commit SVN.2.查看是谁动了我的代码,右键 tortoise 后查看 log 日志.3.文件被别人删除,在空白处右击,show log,可以 ...

  10. css总结7:盒子模型理解

    1 盒子模型 1.1盒子模型的盒子:     以博客园页面为例: 1.2盒子内部构造:边框(border).内容(content).填充(padding).边界(margin)---CSS盒子模式都具 ...