CF #367 DIV2 E
直接使用指针,交换时交换矩阵周围的指针即可。
#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的更多相关文章
- 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, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...
- CodeForces #367 div2 D Trie
题目链接:Vasiliy's Multiset 题意:这里有一个set容器,有三种操作,+ num, - num, ? num,分别代表往容器里加上num,或者拿走num,或着从容器里找一个数temp ...
- CodeForces #367 div2 C
题目链接: Hard problem 题意:每个字符串可以选择反转或者不反转,给出反转每个字符串的代价,问使最少的代价使得这个字符串序列成字典序. dp[i][j] = x : 第一维是第i个字符串, ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
随机推荐
- jq一些常用的交互效果
jq回到顶部: //回到顶部 $(window).scroll(function() { //执行处理的代码 var a = document.body.scrollTop; if($(documen ...
- C# 获取文件编码
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- CAD使用GetxDataString读数据(com接口)
主要用到函数说明: MxDrawEntity::GetxDataString2 读取一个字符扩展数据,详细说明如下: 参数 说明 [in] LONG lItem 该值所在位置 [out, retval ...
- vue工程化之公有CSS、JS文件
1.关于公共的css 在src下面新建public.css,然后在main.js中引入进来 import '@/public.css',这样所有页面中都会使用这个样式了,如果只是部分页面需要,那还是不 ...
- 02Document Type Definition
Document Type Definition 1. Document Type Definition DTD(Document Type Definition)文件格式定义作用是给予文件一种格(T ...
- [python] 时间序列分析之ARIMA
1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量 进行观察测量,将在一系列时刻 所得到的离散数字组成的序列集合,称之为时间序列. 时间序列分析是根据系统观察得到的时间序列数据, ...
- copy on write
yl::string CBaseAutopProcessor::AddAuthorizedInfo(const yl::string & strOriginalUrl, const yl::s ...
- luogu 2-SAT 问题
题目大意:给出n个bool变量,以及m个条件,条件为x,vx,y,vy,表示 x == vx || y == vy . 求匹配. 题解: 最近新学了一下2-SAT算法.2-SAT指有若干个bool变量 ...
- [Python3网络爬虫开发实战] 1.4.2-MongoDB安装
MongoDB是由C++语言编写的非关系型数据库,是一个基于分布式文件存储的开源数据库系统,其内容存储形式类似JSON对象,它的字段值可以包含其他文档.数组及文档数组,非常灵活. MongoDB支持多 ...
- 从yii2框架中的di容器源码中了解反射的作用
反射简介 参考官方简介的话,PHP 5 具有完整的反射 API,添加了对类.接口.函数.方法和扩展进行反向工程的能力. 此外,反射 API 提供了方法来取出函数.类和方法中的文档注释. YII2框架中 ...