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 ...
随机推荐
- jmeter 连接 sqlite 进行压力测试
- node.js入门之一
简单的说 Node.js 就是运行在服务端的 JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事件驱动I/O服务端Ja ...
- excel vba 高级过滤
excel vba 高级过滤 Sub shaixuan() Dim database As Range '定义数据区域 Dim criteria_range As Range '定义条件区域 Dim ...
- 迅为iMX6UL开发板低功耗高能效开发平台
迅为i.MX 6UL开发板基于ARM Cortex-A7内核,主频高达528 MHz,内存:512MDDR3,存储:8G EMMC,支持2路CAN,2路百兆以太网,4路USB HOST,8路串口,以及 ...
- sql server update+select(子查询修改)20190304
if OBJECT_ID('tempdb..##t2') is not null drop table ##t2;create table ##t2( a int, b int, c datetime ...
- JFinal项目eclipse出现the table mapping of model: com.gexin.model.scenic.Scenic not exists or the ActiveRecordPlugin not start.
JFinal项目eclipse出现the table mapping of model: com.gexin.model.scenic.Scenic not exists or the ActiveR ...
- poj3134 Power Calculus
题目描述: 你现在有x^1,每动一步可以用当前存在的x^a和x^b获得x^(a+b)或x^(abs(a-b)).给出n(n<=1000),求最少多少步能得到x^n. 题解: IDDFS.枚举步数 ...
- Ubuntu环境修改IP地址方法
ubuntu环境修改IP地址方法和CentOS系统修改方法不太一样.ubuntu系统修改IP地址方法如下: 编辑/etc/network/interfaces,增加以下内容: auto eth0 if ...
- selenium实战演练
利用selenium以及pyquery,爬取当当网图书信息,并且将数据存入文件以及MongoDB数据库中. 配置文件: key="python" MONGO_URL='localh ...
- 零基础入门Python数据分析,只需要看懂这一张图,附下载链接!
摘要 在做数据分析的过程中,经常会想数据分析到底是什么?为什么要做数据数据分析?数据分析到底该怎么做?等这些问题.对于这些问题,一开始也只是有个很笼统的认识. 最近这两天,读了一下早就被很多人推荐的& ...