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)\) 上有出租车,每 ...
随机推荐
- Quartz表达式生成器
Java版的Quartz表达式生成器,同时适用于Quartz.net(免费下载) Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2 ...
- asp.net内部原理3
asp.net内部原理(三) 第三个版本 (最详细的版本) 前言: 今天继续吧这个系列补齐,这几天公司的项目比较忙,回到家已经非常的累了,所以也没顾得上天天来这里分享一些东西和大家一起探讨,但是今天晚 ...
- iOS获取程序运行平台
下面这个博客里面写的很清楚 http://blog.sina.com.cn/s/blog_890a737301014fim.html
- [网络编程]VS2010+OpenSSL安装与初步了解
OpenSSL简介 功能作用:SSL(Secure Socket Layer)是netscape公司提出的主要用于web的安全通信标准,分为2.0版和3.0版.TLS(Transport Layer ...
- IceMx.Mvc 我的js MVC 框架 三、动手来写一个评论模块儿
介绍 本人菜鸟,一些自己的浅薄见解,望各位大神指正. 本框架有以下优点 1.简单(调用简单.实现简单.不过度设计) 2.视图.控制器.模型分离(分离对于维护十分有必要) 3.组件化(每一个mvc模块儿 ...
- Redis系统学习 三、使用数据结构
前言:上一章,简单介绍了5种数据结构,并给出了一些用例.现在是时候来看看一些高级的,但依然很常见的主题和设计模式 一.大O表示法(Big O Notation ) 常用时间复杂度O(1)被认为是最快速 ...
- hdu4277 USACO ORZ
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Good Vim plugin for python [Vim python mode]
Here I got a very neat plugin for vim which is awesome indeed. It's from youtube years before. So le ...
- python JSON API duckduckgo search engine 使用duckduckgo API 尝试搜索引擎
The duckduckgo.com's search engine is very neat to use. Acutally it has many things to do with other ...
- DEV gridcontrol 设置行数据超宽换行
第一 在main > columns 的 某个gridcolumn下的 columnEdit为新建为 repositoryitemmemoedit 第二 repositor下的optionvie ...