// 十字链表 Codeforces Round #367 E Working routine
// 题意:给你一个矩阵,q次询问,每次交换两个子矩阵,问最后的矩阵
// 思路:暴力肯定不行。我们可以每个元素建立十字链表,记录右边和下边的元素,和每个元素的下标(从0开始),每次询问只需要交换四条边的指向即可。
// 本题要建立(n+1)*(m+1)的矩阵 #include <bits/stdc++.h>
using namespace std;
#define LL long long
const double inf = 123456789012345.0;
const LL MOD =100000000LL;
const int N =*;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int n,m,q;
struct node{
int v,r,d;
}a[N]; int chg(int y,int x){
return y*(m+)+x;
} int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[chg(i,j)].v);
}
} for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
a[chg(i,j)].r=chg(i,j+);
a[chg(i,j)].d=chg(i+,j);
}
}
while(q--){
int x1,y1,x2,y2,h,w;
scanf("%d%d%d%d%d%d",&y1,&x1,&y2,&x2,&h,&w);
int p1=,p2=;
for(int i=;i<y1;i++) p1=a[p1].d;
for(int i=;i<x1;i++) p1=a[p1].r;
for(int i=;i<y2;i++) p2=a[p2].d;
for(int i=;i<x2;i++) p2=a[p2].r;
int t1=p1;
int t2=p2;
for(int i=;i<=h;i++){
t1=a[t1].d;
t2=a[t2].d;
swap(a[t1].r,a[t2].r);
}
for(int i=;i<=w;i++){
t1=a[t1].r;
t2=a[t2].r;
swap(a[t1].d,a[t2].d);
}
t1=p1,t2=p2;
for(int i=;i<=w;i++){
t1=a[t1].r;
t2=a[t2].r;
swap(a[t1].d,a[t2].d);
}
for(int i=;i<=h;i++){
t1=a[t1].d;
t2=a[t2].d;
swap(a[t1].r,a[t2].r);
}
}
int p=;
for(int i=;i<=n;i++){
p=a[p].d;
int q=p;
for(int j=;j<=m;j++){
q=a[q].r;
printf("%d ",a[q].v);
}
printf("\n");
}
return ;
}

十字链表 Codeforces Round #367 E Working routine的更多相关文章

  1. Codeforces Round #367 (Div. 2) (A,B,C,D,E)

    Codeforces Round 367 Div. 2 点击打开链接 A. Beru-taxi (1s, 256MB) 题目大意:在平面上 \(n\) 个点 \((x_i,y_i)\) 上有出租车,每 ...

  2. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)

    Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  4. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  5. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  6. trie树 Codeforces Round #367 D Vasiliy's Multiset

    // trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 / ...

  7. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset

    题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...

  8. Codeforces Round #367 (Div. 2) C. Hard problem

    题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...

  9. Codeforces Round #367 (Div. 2) 套题

    吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include & ...

随机推荐

  1. static int和static final int的区别

    1.static变量 按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或类变量:另一种是没有被static修饰的变量,叫实例变量.两者的区别是: 对于静态变量在内 ...

  2. Android Studio 初探

    前言 上周由于写了一篇关于"Eclipse+ADT+Android SDK 搭建安卓开发环境" 的博文,其他博主们表示相当的不悦,都什么年代了还用Eclipse+ADT开发安卓应用 ...

  3. 基于SMB协议的共享文件读写 博客分类: Java

    基于SMB协议的共享文件读写 博客分类: Java   一.SMB协议 SMB协议是基于TCP-NETBIOS下的,一般端口使用为139,445. 服务器信息块(SMB)协议是一种IBM协议,用于在计 ...

  4. 使用phantomjs对页面进行截图

    本文章参考了使用phantomjs操作DOM并对页面进行截图需要注意的几个问题 及 phantomjs使用说明 这两篇文章,初次接触phantomjs的童鞋可以去看下这两篇原文 在学习中可以看下 ph ...

  5. IO多路复用的几种实现机制的分析

    http://blog.csdn.net/zhang_shuai_2011/article/details/7675797 select,poll,epoll都是IO多路复用的机制.所谓I/O多路复用 ...

  6. linux系统的文件类型学习

    linux是一个文件型操作系统,在linux下一切皆文件. 目录.字符设备.块设备.管道.套接字.符号连接文件等在linux下统统都是文件. linux下的文件类型分为以下几种类型: 1. 正规文件, ...

  7. ExtJs自学教程(2):从DOM看EXTJS

    <二> 从DOM看EXTJS 看标题可能有人会问,为啥好好的例子不看,得从DOM看起呢?答案是目标只为了一个:自运行结果把EXTJS看得更清楚点 首先,要看得靠点工具,带点放大镜什么吧?对 ...

  8. Android开发之创建桌面快捷方式

    Android创建桌面快捷方式就是在桌面这个应用上创建一个快捷方式,桌面应用:launcher2 通过查看launcher2的清单文件: <!-- Intent received used to ...

  9. bzoj1132

    每次都选最左边的点,然后以这个点为原点 统计和这个点构成的三角形面积和 不难想到极角排序然后由叉积很容易求出 shl ; eps=1e-8; var i,j,k,m,n:longint; x,y:.. ...

  10. Linux busybox mount -a fstab

    /*********************************************************************** * Linux busybox mount -a fs ...