#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. Hadoop Serialization -- hadoop序列化详解 (2)

    回顾: 回顾序列化,其实原书的结构很清晰,我截图给出书中的章节结构: 序列化最主要的,最底层的是实现writable接口,wiritable规定读和写的游戏规则 (void write(DataOut ...

  2. 【转】Spring事务介绍

    1. 事务的特性:ACID 原子性(Atomicity):事务是一个原子操作,由一系列动作组成.事务的原子性确保动作要么全部完成,要么完全不起作用. 一致性(Consistency):一旦事务完成(不 ...

  3. Hadoop之HDFS(三)HDFS的JAVA API操作

    HDFS的JAVA API操作 HDFS 在生产应用中主要是客户端的开发,其核心步骤是从 HDFS 提供的 api中构造一个 HDFS 的访问客户端对象,然后通过该客户端对象操作(增删改查)HDFS ...

  4. memcache 随笔

    第一次用可能有很多不足的地方  以后慢慢改进. memcache  是一个简单的键/值对    是通过键和值储存信息到memcache中 ,通过特定的键请求来返回信息. 信息会无限期的保留在内存中 : ...

  5. JSP页面使用EL表达式出现的问题:javax.el.PropertyNotFoundException: Property 'ID' not found on type java.lang.Str

    问题描述: 1. 后台返回到JSP前台的的list,在jsp页面使用EL表达式遍历时出现如下问题:javax.el.PropertyNotFoundException: Property 'ID' n ...

  6. JavaScript -- Array中的push()方法和concat()方法介绍

    Array => push()方法向数组的末尾添加一个或者多个元素,也就是说它会改变数组本身 concat() => concat()方法用于连接2个或者多个数组,但它的特殊之处在于,它会 ...

  7. CSS3 grayscale滤镜图片变黑白

    1. 使整个页面的图片都变成灰色的,代码如下. html{     font-size: 100%;     -webkit-text-size-adjust: none;    -ms-text-s ...

  8. 理解 RESTful WebService

    RESTful 服务遵循REST(Representational State Transfer)的架构风格,中文翻译为:表现层状态转化 对于所有的CRUD(Read/Create/Update/De ...

  9. Azure 网站、云服务和虚拟机比较

    最后更新时间(英文版):09/24/2014 最后更新时间(中文版):04/11/2015 Azure 提供几种方式托管 web 应用程序,如 Azure 网站.云服务和虚拟机.查看这些不同的选项后, ...

  10. Slf4j MDC 使用和 基于 Logback 的实现分析

    前言 如今,在 Java 开发中,日志的打印输出是必不可少的, 关于  有了日志之后,我们就可以追踪各种线上问题.但是,在分布式系统中,各种无关日志穿行其中,导致我们可能无法直接定位整个操作流程.因此 ...