十字链表 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 & ...
随机推荐
- iOS使用Charts框架绘制—柱形图
首先看一下最终要实现的效果: 最终效果 一.初始化barChartView 绘制柱形图需要用到BarChartView这个类,下面是初始化代码: self.barChartView = [[BarCh ...
- CString, QString, char*之间的转换(包括VC编译开关)
传给未分配内存的const char* (LPCTSTR)指针. CString cstr(asdd); const char* ch = (LPCTSTR)cstr; ch指向的地址和cstr相同. ...
- WCF入门(十)---WCF事务
事务处理在WCF(Windows Communication Foundation)是一套遵循一些性质,统称为ACID的操作.这里,如果一个操作出现故障,整个系统就会自动失败.如网上订单生成,就可能使 ...
- *IDEA真好用
使用maven做开发,在编辑pom.xml文件时
- C++:函数模板与模板函数
6.1 模板的概念 C++允许用同一个函数定义函数,这些函数的参数个数和参数类型不同.例如求最大值的max函数, int max(int x,int y) { return (x>y ...
- C# App.config 详解
读语句: String str = ConfigurationManager.AppSettings["DemoKey"]; 写语句: Configuration cfa = ...
- Ubuntu中Eclipse安装与配置
安装Eclipse: 第一种是通过Ubuntu自带的程序安装功能安装Eclipse,应用程序 ->Ubtuntu软件中心,搜Eclipse安装即可.第二种方法是用命令:应用程序->附件-& ...
- C++ STL之排序算法
排序算法和查找算法差不多,也涉及到迭代器区间问题,关于该问题的注意事项就不在啰嗦了 一.全部排序sort.stable_sort sort是一种不稳定排序,使用时需要包含头文件algorithm 默认 ...
- MemSQL start[c]up Round 2 - online version(DP)
只有小写字母 那>=2600的直接找单字母串长度大于等于100的就可以了 <2600 的dp找最长回文串 #include <iostream> #include<cst ...
- 高斯消元 分析 && 模板 (转载)
转载自:http://hi.baidu.com/czyuan_acm/item/dce4e6f8a8c45f13d7ff8cda czyuan 先上模板: /* 用于求整数解得方程组. */ #inc ...