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 ...
随机推荐
- leetcode_951. Flip Equivalent Binary Trees_二叉树遍历
https://leetcode.com/problems/flip-equivalent-binary-trees/ 判断两棵二叉树是否等价:若两棵二叉树可以通过任意次的交换任意节点的左右子树变为相 ...
- pycharm 编写前端代码一些小技巧
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...
- 编程规范:allocator
一.作用 标准库allocator类定义在头文件memory中,它帮助我们将内存分配和对象构造分离开来 allocator<T> a //定义一个名为a的allocator对象,它可以为类 ...
- JAVA基础——IO流字符流
字符流 字节流提供了处理任何类型输入/输出操作的功能(因为对于计算机而言,一切都是0和1,只需把数据以字节形式表示就够了),但它们不可以直接操作Unicode字符,因为上一篇文章写了,一个Unicod ...
- switch、try-catch
记录 1. 使用对象代替 switch 和 if-else 2. 根据返回数据是否能转成对象,取值 如果返回是数字字符串,直接返回,如果返回是对象,取对应的key值,再返回 其它情况,返回空 {{ o ...
- ''tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[?]'' 错误分析
这是tensorflow 一个经常性错误,错误的原因在于:显卡内存不够. 解决方法就是降低显卡的使用内存,途径有以下几种措施: 1 减少Batch 的大小 2 分析错误的位置,在哪一层出现显卡不够,比 ...
- Centos7 静态IP配置
先将虚拟机设置为桥接模式: 虚拟机网络将VMnet8设置为NAT模式: 查看本机IP地址,ipconfig,记住ipv4地址和默认网关地址,等会配置的时候要用 启动Centos,进入终端模式,设置IP ...
- jmeter 接口测试
web接口测试工具: 手工测试的话可以用postman ,自动化测试多是用到 Jmeter(开源).soupUI(开源&商业版). 下面将对前一篇Postman做接口测试中的接口用Jmeter ...
- 100ns周期200ns的正脉冲波形形状描述
用FPGA控制16245产生正脉冲,正脉冲的形状是上升会有过冲现象,下降会有震荡产生,做了个实验室,用同轴电缆承载这种信号,在同轴电缆的末端会产生的波形是标准的衰减震荡. (简单的入pcb,经过继电器 ...
- Nginx学习总结(4)——负载均衡session会话保持方法
负载均衡时,为了保证同一用户session会被分配到同一台服务器上,可以使用以下方法: 1.使用cookie 将用户的session存入cookie里,当用户分配到不同的服务器时,先判断服务器是否存在 ...