#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. Resin 的watchdog(看门狗)介绍和resin负载均衡实现

    为了稳定和安全,Resin使用一个独立的watchdog进程来启动和监视Resin服务器.watchdog连续你检测Resin服务器的状态,如果其没有反应或者迟钝,将会重启Resin服务器进程.大多数 ...

  2. swfupload上传文件数量限制之setStats()

    使用swfupload仿赶集的图片上传 SWFUpload是一个基于flash与javascript的客户端文件上传组件. handlers.js文件 完成文件入列队(fileQueued) → 完成 ...

  3. 819. Most Common Word 统计高频词(暂未被禁止)

    [抄题]: Given a paragraph and a list of banned words, return the most frequent word that is not in the ...

  4. java 解析xml(dom4j.jar)

    先导入jar包 <?xml version="1.0" encoding="UTF-8"?> <companys> <compan ...

  5. 2-chrome无法添加扩展程序

    1.更多工具->拓展程序->打开开发者模式->重启浏览器 2.将拓展程序拖入,确认安装

  6. selenium+phantomjs解析JS

    背景知识: PhantomJS 是一个基于WebKit的服务器端 JavaScript API.它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS 选择器, J ...

  7. html页面的局部刷新

    有时候我们在做一个动态/静态网页,网页中的某部分需要从服务器获取值但是不能把整个页面都提交到服务器,也就是要对页面做局部刷新,也就是对整个网页无刷新更新值.在这种情况下就需要用JS和XMLHttpRe ...

  8. Eclipse工具

    1 ArrayList的常见方法 * a: add(参数) 向集合中添加元素 * b: get(int index) 取出集合中的元素,get方法的参数,写入索引 * c: size() 返回集合的长 ...

  9. Dapper多表查询

    1对1 //文章 public class Post { public int ID { get; set; } public string Title { get; set; } public st ...

  10. layer弹出框插件参数及方法介绍

    layerui下载:http://www.layui.com 更多参数请阅读开发文档:http://www.layui.com/doc/modules/layer.html Layui 是一款采用自身 ...