CodeForces 706E Working routine
十字链表。
开一个十字链表,矩阵中每一格作为一个节点,记录五个量:
$s[i].L$:$i$节点左边的节点编号
$s[i].R$:$i$节点右边的节点编号
$s[i].U$:$i$节点上面的节点编号
$s[i].D$:$i$节点下面的节点编号
$s[i].V$:$i$节点存储的值
每次操作,只要把四个边上的那些边拆掉,重新连上新的边就可以了。时间复杂度:$O(qn)$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} const int maxn=;
int n,m,k,sz;
struct X { int u,d,l,r,v; }s[maxn*maxn];
int a[maxn*maxn],id[maxn][maxn]; int main()
{
scanf("%d%d%d",&n,&m,&k); for(int i=;i<=n;i++) id[i][]=sz++; for(int j=;j<=m;j++) id[][j]=sz++;
for(int i=;i<=n;i++) for(int j=;j<=m;j++) id[i][j]=sz++;
for(int i=;i<=n;i++) id[i][m+]=sz++; for(int j=;j<=m;j++) id[n+][j]=sz++; for(int i=;i<=n+;i++)
{
for(int j=;j<=m+;j++)
{
s[id[i][j]].l=-; s[id[i][j]].r=-; s[id[i][j]].u=-; s[id[i][j]].d=-; if(j->=) s[id[i][j]].l=id[i][j-]; if(j+<=m+) s[id[i][j]].r=id[i][j+];
if(i->=) s[id[i][j]].u=id[i-][j]; if(i+<=n+) s[id[i][j]].d=id[i+][j];
}
} for(int i=;i<=n;i++) for(int j=;j<=m;j++) scanf("%d",&s[id[i][j]].v); for(int i=;i<=k;i++)
{
int r1,c1,r2,c2,h,w;
scanf("%d%d%d%d%d%d",&r1,&c1,&r2,&c2,&h,&w); int p1,p2,t1,t2,t3,t4,P1,P2; p1=r1,p2=r2;
for(int j=;j<=c1;j++) p1=s[p1].r; for(int j=;j<=c2;j++) p2=s[p2].r; P1=p1,P2=p2;
for(int j=;j<=w-;j++) P1=s[P1].r; for(int j=;j<=w-;j++) P2=s[P2].r;
for(int j=;j<=h-;j++) P1=s[P1].d; for(int j=;j<=h-;j++) P2=s[P2].d; t1=p1,t2=p2; t3=s[p1].l; t4=s[p2].l;
for(int j=;j<=h;j++) swap(s[t1].l,s[t2].l), t1=s[t1].d, t2=s[t2].d;
for(int j=;j<=h;j++) swap(s[t3].r,s[t4].r), t3=s[t3].d, t4=s[t4].d; t1=p1,t2=p2; t3=s[p1].u; t4=s[p2].u;
for(int j=;j<=w;j++) swap(s[t1].u,s[t2].u), t1=s[t1].r, t2=s[t2].r;
for(int j=;j<=w;j++) swap(s[t3].d,s[t4].d), t3=s[t3].r, t4=s[t4].r; p1=P1,p2=P2; t1=p1,t2=p2; t3=s[p1].d; t4=s[p2].d;
for(int j=;j<=w;j++) swap(s[t1].d,s[t2].d), t1=s[t1].l, t2=s[t2].l;
for(int j=;j<=w;j++) swap(s[t3].u,s[t4].u), t3=s[t3].l, t4=s[t4].l; t1=p1,t2=p2; t3=s[p1].r; t4=s[p2].r;
for(int j=;j<=h;j++) swap(s[t1].r,s[t2].r), t1=s[t1].u, t2=s[t2].u;
for(int j=;j<=h;j++) swap(s[t3].l,s[t4].l), t3=s[t3].u, t4=s[t4].u; }
for(int i=;i<=n;i++)
{
int p=i;
for(int j=;j<=m;j++)
p=s[p].r, printf("%d ",s[p].v);
printf("\n");
} return ;
}
CodeForces 706E Working routine的更多相关文章
- 【链表】【模拟】Codeforces 706E Working routine
题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,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 ...
- Working routine CodeForces - 706E (链表)
大意: 给定矩阵, q个操作, 每次选两个子矩阵交换, 最后输出交换后的矩阵 双向十字链表模拟就行了 const int N = 1500; int n, m, q; struct _ { int v ...
- Magolor的数据结构作业
\(CodeForces 706E ~Working routine\) 给出一个矩阵,每次操作交换两个子矩阵,求最后状态. 使用链表存储,每次交换后,影响到的之后矩阵边缘的指针,暴力修改. \(~~ ...
- 十字链表 Codeforces Round #367 E Working routine
// 十字链表 Codeforces Round #367 E Working routine // 题意:给你一个矩阵,q次询问,每次交换两个子矩阵,问最后的矩阵 // 思路:暴力肯定不行.我们可以 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- Codeforces Round #196 (Div. 2) B. Routine Problem
screen 尺寸为a:b video 尺寸为 c:d 如果a == c 则 面积比为 cd/ab=ad/cb (ad < cb) 如果b == d 则 面积比为 cd/ab=cb/ad (c ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- 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)\) 上有出租车,每 ...
随机推荐
- Jquery EasyUI中treegrid
Jquery EasyUI中treegrid的中右键菜单和一般按钮同时绑定事件时的怪异事件 InChatter系统开源聊天模块前奏曲 最近在研究WCF,又因为工作中的项目需要,要为现有的系统增加一 ...
- DeviceIoControl方式 sys和exe通信
常识: IRP:I/O Request Package 即输入输出请求包 exe和sys通信时,exe会发出I/O请求.操作系统会将I/O请求转化为相应的IRP数据, 不同类型传递到不同的d ...
- YSlow的性能测试提示
Add an Expires or a Cache-Control Header tag: server There are two aspects to this rule: For static ...
- jQuery中的事件监听方式及异同点
jQuery中的事件监听方式及异同点 作为全球最知名的js框架之一,jQuery的火热程度堪称无与伦比,简单易学的API再加丰富的插件,几乎是每个前端程序员的必修课.从读<锋利的jQuery&g ...
- Form.Close跟Form.Dispose
关于Form.Close跟Form.Dispose 我们在Winform开发的时候,使用From.Show来显示窗口,使用Form.Close来关闭窗口.熟悉Winform开发的想必对这些非常熟悉 ...
- go语言中的数组切片:特立独行的可变数组
go语言中的数组切片:特立独行的可变数组 初看go语言中的slice,觉得是可变数组的一种很不错的实现,直接在语言语法的层面支持,操作方面比起java中的ArrayList方便了许多.但是在使用了一段 ...
- python文件的中文处理以及个人思路
环境:ubuntu12.04 python2.7 涉及:ascii,utf-8,gbk,gb2312 首先说下个人处理过程中遇到的问题: 任务是这样:有大概4000个txt,将他们合并到一个文件里, ...
- C/C++单链表
C/C++单链表 先看例子,例1:定义链表 //定义链表 struct stu { int name; int age; struct stu *next; }; 用一组地址任意的存储单元存放线性表中 ...
- Cocoa框架
Cocoa提供了用于存放数字和字符串的通用数据类型的实际的类.非正式地可以将这些称为值类或基本值类. Cocoa框架本身封装了三个独立的框架:Foundation基本框架.AppKit框架和核心数据框 ...
- Nunit NMock Ncover单元测试
Nunit中如何进行事务性单元测试 单元测试要求:单元测试方法并不真正去变更数据库,也就是说单元测试不依赖于数据库中的数据.那我们如何解决执行单元测试方法后,不变更数据库中数据呢? 一般的解决方案 ...