十字链表 Codeforces Round #367 E Working routine
// 十字链表 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的更多相关文章
- 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)\) 上有出租车,每 ...
- 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 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- trie树 Codeforces Round #367 D Vasiliy's Multiset
// trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 / ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset
题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- Codeforces Round #367 (Div. 2) 套题
吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include & ...
随机推荐
- Rebound-Android的弹簧动画库
Rebound是facebook出品的一个弹簧动画库,与之对应的IOS版本有一个pop动画库,也是非常的强大给力.Facebook真是互联网企业中的楷模,开源了很多的实用开源库,大赞一个!!! 讲解R ...
- import java.util.Scanner;
一.扫描控制台输入 当通过new Scanner(System.in)创建一个Scanner,控制台会一直等待输入,,,,,,,直到敲回车键结束,把所输入的内容传给Scanner,作为扫描对象 ...
- 54. Spiral Matrix
题目: Given a matrix of m x n elements (m rows, ncolumns), return all elements of the matrix in spiral ...
- openfire 介绍安装使用
Openfire 采用Java开发,开源的实时协作(RTC)服务器基于XMPP(Jabber)协议.Openfire安装和使用都非常简单,并利用Web进行管理.单台服务器可支持上万并发用户.您可以使用 ...
- UVa 1402 Runtime Error 伸展树
Runtime Error 到现在连样例也跑不出来!!! 调试了一晚上快要死了…… 知道错在哪里但是不会改,代码先扔在这里吧.看来不能太依赖模板啊orz…… #include <cstdio&g ...
- oracle lsnrctl status|start|stop
[oracle@redhat4 ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 06-OCT-2015 ...
- C结构体之位域(位段)
C结构体之位域(位段) 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C ...
- LA 5846 (计数) Neon Sign
从反面考虑,统计非单色三角形的个数. 如果从一个点出发两条不同颜色的边,那么这三个点一定构成一个非单色三角形. 枚举一个顶点,统计从这个点出发的红边的个数a[i]和蓝边的个数n - 1 - a[i], ...
- wdcp系统升级mysql5.7.11
1.下载解压 下载地址为:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ...
- 【C#学习笔记】检测进程是否存在并关闭
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...