直接使用指针,交换时交换矩阵周围的指针即可。

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int N = 1005; struct dl{
int v;
struct dl *d, *r;
}e[N][N]; int main(){
int n, m , q;
scanf("%d%d%d", &n, &m, &q);
int x, y, s, t, h, w;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++)
scanf("%d", &e[i][j].v);
} for(int i = 0; i <= n; i++){
for(int j = 0; j <= m; j++){
e[i][j].r = &e[i][j + 1];
e[i][j].d = &e[i + 1][j];
}
} for(int i = 1; i <= q; i++){
scanf("%d%d%d%d%d%d", &x, &y, &s, &t, &h, &w);
dl *pos1, *pos2;
pos2 = pos1 = &e[0][0];
int th = h, tw = w;
while(-- x) pos1 = pos1 -> d;
while(-- y) pos1 = pos1 -> r;
th = h, tw = w;
while(-- s) pos2 = pos2 -> d;
while(-- t) pos2 = pos2 -> r; dl* tp1 = pos1, *tp2 = pos2; for(int r = 1; r <= h; r++){
pos1 = pos1 -> d;
pos2 = pos2 -> d;
swap(pos1 -> r, pos2 -> r);
} for(int c = 1; c <= w; c++){
pos1 = pos1 -> r;
pos2 = pos2 -> r;
swap(pos1 -> d, pos2 -> d);
} for(int c = 1; c <= w; c++){
tp1 = tp1 -> r;
tp2 = tp2 -> r;
swap(tp1 -> d, tp2 -> d);
} for(int r = 1; r <= h; r ++){
tp1 = tp1 -> d;
tp2 = tp2 -> d;
swap(tp1 -> r, tp2 -> r);
}
} dl *pos1 = &e[0][0]; for(int i = 1; i <= n; i++){
pos1 = pos1 -> d;
dl *tmp = pos1;
for(int j = 1; j <= m; j++){
pos1 = pos1 ->r;
if(j == 1)
printf("%d", pos1 ->v);
else printf(" %d", pos1 ->v);
}
puts("");
pos1= tmp;
} return 0;
}

  

CF #367 DIV2 E的更多相关文章

  1. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  2. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

  3. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  4. CF#581 (div2)题解

    CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...

  5. [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)

    题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...

  6. CodeForces #367 div2 D Trie

    题目链接:Vasiliy's Multiset 题意:这里有一个set容器,有三种操作,+ num, - num, ? num,分别代表往容器里加上num,或者拿走num,或着从容器里找一个数temp ...

  7. CodeForces #367 div2 C

    题目链接: Hard problem 题意:每个字符串可以选择反转或者不反转,给出反转每个字符串的代价,问使最少的代价使得这个字符串序列成字典序. dp[i][j] = x : 第一维是第i个字符串, ...

  8. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

  9. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

随机推荐

  1. C++ 异常处理(try catch throw)、命名空间

    一.c++工具 模板(函数模板.类模板).异常处理.命名空间等功能是c++编译器的功能,语言本身不自带,这些功能已经成为ANSI C++标准了,建议所有的编译器都带这些功能,早期的c++是没有这些功能 ...

  2. sqllite相关总结

    一,sqlite 简介 前面写了一篇博文讲如何在 C# 中使用 ADO 访问各种数据库,在移动开发和嵌入式领域也有一个轻量级的开源关系型数据库-sqlite.它的特点是零配置(无需服务器),单磁盘文件 ...

  3. ios打电话发短信接口

    电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...

  4. vue跨域解决方法 及设置api路径方法

    vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No 'Access-Control-Allow-Origin' header is prese ...

  5. LUA-点号和冒号

    由于LUA中是模拟类,没有class, 所以这里是使用.号来访问实例的成员 re.SetActive(re, re.activeSelf == false); 而冒号:  则是种语法糖,省略了上面代码 ...

  6. php与mysql事物处理

    PHP与MYSQL事务处理 mysql事物特性 (原子性,一致性,隔离性,持久性) /*MYSQL的事务处理主要有两种方法.1.用begin,rollback,commit来实现begin 开始一个事 ...

  7. Spring接收web请求参数的几种方式

    1 查询参数 请求格式:url?参数1=值1&参数2=值2...同时适用于GET和POST方式spring处理查询参数的方法又有几种写法: 方法一:方法参数名即为请求参数名 // 查询参数1 ...

  8. 13Spring通过注解配置Bean(1)

    配置Bean的形式:基于XML文件的方式:基于注解的方式(基于注解配置Bean:基于注解来装配Bean的属性) 下面介绍基于注解的方式来配置Bean. ——组件扫描(component scannin ...

  9. Python之爬虫-中国大学排名

    Python之爬虫-中国大学排名 #!/usr/bin/env python # coding: utf-8 import bs4 import requests from bs4 import Be ...

  10. LeetCode(4)Median of Two Sorted Arrays

    题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...