Working routine CodeForces - 706E (链表)
大意: 给定矩阵, q个操作, 每次选两个子矩阵交换, 最后输出交换后的矩阵
双向十字链表模拟就行了
const int N = 1500;
int n, m, q;
struct _ {
int v,l,r,u,d;
} f[N*N];
int ans[N][N];
int has(int i,int j) {return 1010*(i+2)+(j+2);}
int get(int i,int j) {
int r = f[has(0,j)].d;
REP(k,1,i-1) r=f[r].d;
return r;
} void pr() {
REP(j,1,m) {
int x = get(1,j);
REP(i,1,n) ans[i][j]=f[x].v,x=f[x].d;
}
REP(i,1,n) {
REP(j,1,m) printf("%d ", ans[i][j]);hr;
}
} int main() {
scanf("%d%d%d", &n, &m, &q);
REP(i,1,n) REP(j,1,m) {
_ &t = f[has(i,j)];
scanf("%d", &t.v);
t.l=has(i,j-1);
t.r=has(i,j+1);
t.u=has(i-1,j);
t.d=has(i+1,j);
}
REP(i,1,m) {
f[has(0,i)].d=has(1,i);
f[has(n+1,i)].u=has(n,i);
}
REP(i,1,n) {
f[has(i,m+1)].l=has(i,m);
f[has(i,0)].r=has(i,1);
}
REP(i,1,q) {
int a, b, c, d, h, w;
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &h, &w);
int x = get(a,b), y = get(c,d);
REP(i,1,w) {
swap(f[f[x].u].d,f[f[y].u].d);
swap(f[x].u,f[y].u);
if (i!=w) x = f[x].r, y = f[y].r;
}
REP(i,1,h) {
swap(f[f[x].r].l,f[f[y].r].l);
swap(f[x].r,f[y].r);
if (i!=h) x = f[x].d, y = f[y].d;
}
REP(i,1,w) {
swap(f[f[x].d].u,f[f[y].d].u);
swap(f[x].d,f[y].d);
if (i!=w) x = f[x].l, y = f[y].l;
}
REP(i,1,h) {
swap(f[f[x].l].r,f[f[y].l].r);
swap(f[x].l,f[y].l);
x = f[x].u, y = f[y].u;
}
}
pr();
}
Working routine CodeForces - 706E (链表)的更多相关文章
- 【链表】【模拟】Codeforces 706E Working routine
题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...
- CodeForces 706E Working routine
十字链表. 开一个十字链表,矩阵中每一格作为一个节点,记录五个量: $s[i].L$:$i$节点左边的节点编号 $s[i].R$:$i$节点右边的节点编号 $s[i].U$:$i$节点上面的节点编号 ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- 【CodeForces706E】Working routine(二维链表)
BUPT2017 wintertraining(15) #6B 题意 q次操作,每次把两个给定子矩阵交换,求最后的矩阵.(2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) 题解 用R[ ...
- Codeforces Round #367 (Div. 2) 套题
吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include & ...
- Magolor的数据结构作业
\(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~ ...
- 十字链表 Codeforces Round #367 E Working routine
// 十字链表 Codeforces Round #367 E Working routine // 题意:给你一个矩阵,q次询问,每次交换两个子矩阵,问最后的矩阵 // 思路:暴力肯定不行.我们可以 ...
- [cf div 2 706E] Working routine
[cf div 2 706E] Working routine Vasiliy finally got to work, where there is a huge amount of tasks w ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
随机推荐
- printf("%d",5.01)和printf("%f",5)的输出结果
printf(); printf("%d\n",5.01); printf(); printf(.f); 输出结果: 看到结果,会感觉非常奇怪.1处怎么会输出0呢?2又为何会显示这 ...
- windwos::mutex
线程同步的方式和机制 临界区.互斥区.事件.信号量四种方式 临界区(Critical Section).互斥量(Mutex).信号量(Semaphore).事件(Event)的区别 1.临界区:通过对 ...
- mybatis 3的TypeHandler深入解析(及null值的处理)
最近,在测试迁移公司的交易客户端连接到自主研发的中间件时,调用DAO层时,发现有些参数并没有传递,而在mapper里面是通过parameterMap传递的,因为有些参数为null,这就导致了参数传递到 ...
- 20145314郑凯杰《网络对抗技术》实验9 web安全基础实践
20145314郑凯杰<网络对抗技术>实验9 web安全基础实践 一.实验准备 1.0 实验目标和内容 Web前端HTML.能正常安装.启停Apache.理解HTML,理解表单,理解GET ...
- TensorFlow入门(四) name / variable_scope 的使
name/variable_scope 的作用 欢迎转载,但请务必注明原文出处及作者信息. @author: huangyongye @creat_date: 2017-03-08 refer to: ...
- Python3基础 str find+index 是否存在指定字符串,有则返回第一个索引值
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- windows下的 gvim - su'blime text 的使用
su'blime [s2'blaim] adj. n. 崇高的, 高尚的, 令人尊敬的; 壮丽的, 宏伟的; 出众的; 崇高的人, 壮丽的事物等等. a sublime mission. a subl ...
- POJ 2348 Euclid's Game(博弈)题解
题意:有a,b两个数字,两人轮流操作,每次可以选择两个之中较小的数字,然后另一个数字减去选择数字的任意倍数(不能减到负数),直到其中一个为0,不能操作为败 思路:这题用博弈NP思想,必败点和必胜点之间 ...
- 简单Shell案例
使用shell命令进行左对齐或者右对齐 [root@bj-aws-yace-tbj mnt]# cat test.sh #! /bin/bash file=./test.txt echo -e &qu ...
- poj 2449 Remmarguts' Date 求第k短路 Astar算法
=.=好菜 #include <iostream> #include <cstdio> #include <string.h> #include <cstri ...