NOIP模拟 table - 矩阵链表
题目大意:
给一个n*m的矩阵,每次交换两个大小相同的不重叠的子矩阵,输出最后的矩阵
题目分析:
这题向我们展示了出神入化的链表是如何炼成的。思想都懂,实现是真的需要技术,%%%
用一副链表来表示该矩阵,每个节点记录他的右节点和下节点,这样在交换两个矩阵时,只需要暴力交换两个矩阵的边框,并更新边框外面的相关信息,边框内的信息不用更改(相对位置不变),最后从左上角输出即可。
code
#include<bits/stdc++.h>
using namespace std;
namespace IO{
inline int read(){
int i = 0, f = 1; char ch = getchar();
for(; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
if(ch == '-') f = -1, ch = getchar();
for(; ch >= '0' && ch <= '9'; ch = getchar()) i = (i << 3) + (i << 1) + (ch - '0');
return i * f;
}
inline void wr(int x){
if(x < 0) putchar('-'), x = -x;
if(x > 9) wr(x / 10);
putchar(x % 10 + '0');
}
}using namespace IO;
const int N = 1005, M = 1005003;
int n, m, q, v[M], num[N][N], tot;
int lst[M][2];
inline int get(int x, int y){
int now = num[0][0];
for(int i = 1; i <= x; i++) now = lst[now][1];
for(int i = 1; i <= y; i++) now = lst[now][0];
return now;
}
int main(){
freopen("h.in", "r", stdin);
n = read(), m = read(), q = read();
for(register int i = 1; i <= n; i++)
for(register int j = 1; j <= m; j++)
v[num[i][j] = ++tot] = read();
// for(int i = 1; i <= tot; i++) cout<<v[i]<<endl;
for(register int i = 0; i <= m + 1; i++) num[0][i] = ++tot, num[n + 1][i] = ++tot;
for(register int i = 1; i <= n; i++) num[i][0] = ++tot, num[i][m + 1] = ++tot;
for(register int i = 0; i <= n; i++)
for(register int j = 0; j <= m; j++){
lst[num[i][j]][0] = num[i][j + 1];
lst[num[i][j]][1] = num[i + 1][j];
}
// for(int i = 1; i <= n; i++)
// for(int j = 1; j <= m; j++)
// cout<<i<<" @"<<j<<" "<<lst[num[i][j]][0]<<" "<<lst[num[i][j]][1]<<endl;
for(; q; q--){
int a, b, c, d, h, w;
a = read(), b = read(), c = read(), d = read(), h = read(), w = read();
int pos1 = get(a - 1, b - 1), pos2 = get(c - 1, d - 1);
// cout<<pos1<<" "<<pos2<<endl;
register int t1, t2, ww, hh;
for(t1 = pos1, t2 = pos2, ww = 1; ww <= w; ww++)
swap(lst[t1 = lst[t1][0]][1], lst[t2 = lst[t2][0]][1]);
for(hh = 1; hh <= h; hh++)
swap(lst[t1 = lst[t1][1]][0], lst[t2 = lst[t2][1]][0]);
for(t1 = pos1, t2 = pos2, hh = 1; hh <= h; hh++)
swap(lst[t1 = lst[t1][1]][0], lst[t2 = lst[t2][1]][0]);
for(ww = 1; ww <= w; ww++)
swap(lst[t1 = lst[t1][0]][1], lst[t2 = lst[t2][0]][1]);
}
int now = num[0][0];
for(register int i = 1; i <= n; i++){
for(register int j = 1, t = now = lst[now][1]; j <= m; j++)
cout<<v[t = lst[t][0]]<<" ";
cout<<endl;
}
return 0;
}
NOIP模拟 table - 矩阵链表的更多相关文章
- 2018.08.29 NOIP模拟 table(拓扑排序+建图优化)
[描述] 给出一个表格,N 行 M 列,每个格子有一个整数,有些格子是空的.现在需要你 来做出一些调整,使得每行都是非降序的.这个调整只能是整列的移动. [输入] 第一行两个正整数 N 和 M. 接下 ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- NOI.AC NOIP模拟赛 第三场 补记
NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...
- NOIP模拟题汇总(加厚版)
\(NOIP\)模拟题汇总(加厚版) T1 string 描述 有一个仅由 '0' 和 '1' 组成的字符串 \(A\),可以对其执行下列两个操作: 删除 \(A\)中的第一个字符: 若 \(A\)中 ...
- 2014-10-31 NOIP模拟赛
10.30 NOIp 模拟赛 时间 空间 测试点 评测方式 挖掘机(dig.*) 1s 256M 10 传统 黑红树(brtree.*) 2s 256M 10 传统 藏宝图(treas. ...
- 9.9 NOIP模拟题
9.9 NOIP模拟题 T1 两个圆的面积求并 /* 计算圆的面积并 多个圆要用辛普森积分解决 这里只有两个,模拟计算就好 两圆相交时,面积并等于中间两个扇形面积减去两个三角形面积 余弦定理求角度,算 ...
- 8.1 NOIP模拟11
8.1 NOIP模拟 11 今天上午返校之后,颓了一会,然后下午就开始考试,中午睡着了,然后刚开始考试的时候就困的一匹,我一看T1,woc,这不是之前线段树专题的题啊,和那道题差不多,所以我..... ...
- NOIP模拟赛 6.29
2017-6-29 NOIP模拟赛 Problem 1 机器人(robot.cpp/c/pas) [题目描述] 早苗入手了最新的Gundam模型.最新款自然有着与以往不同的功能,那就是它能够自动行走, ...
- 2019.8.3 [HZOI]NOIP模拟测试12 C. 分组
2019.8.3 [HZOI]NOIP模拟测试12 C. 分组 全场比赛题解:https://pan.baidu.com/s/1eSAMuXk 刚看这题觉得很难,于是数据点分治 k只有1和2两种,分别 ...
随机推荐
- 前台Ajax发送数据给后台
前台发ajax请求给后台 前台代码 let data= [{receiveAdd:receiveAddVal, sendAdd:sendAddVal,distance:distance,goodsNa ...
- hibernate 的映射文件快速生成:使用CodeSmith快速生成映射文件和映射类
一 CodeSmith简介 本文以表自动生成NHibernate的映射文件和映射类的实例来说明一下本软件的使用方法. CodeSmith是一种基于模板的代码生成工具,其使用类似于ASP.NET的语法来 ...
- 对于学习apache软件基金会顶级项目源码的一点思路(转)
ASF的开源项目,为软件行业贡献了太多好的产品和软件思维.学习ASF的项目源码能很大的提升自身的能力.程序运行在服务器上的流程:执行启动脚本(start.sh) -> 指向程序的主方法 -> ...
- LeetCode Algorithm 04_Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted ...
- 各个浏览器/服务器URL最大长度限制
在http协议中,其实并没有对url长度作出限制,往往url的最大长度和用户浏览器和Web服务器有关,不一样的浏览器,能接受的最大长度往往是不一样的,当然,不一样的Web服务器能够处理的最大长度的UR ...
- 防止 Chrome 屏蔽 非官方 扩展程序 教程(一)
说明 Google Chrome,又称 Google 浏览器,是一个由 Google(谷歌)公司开发的网页浏览器.该浏览器是基于其它开源软件所撰写.包含 WebKit,目标是提升稳定性.速度和安全性. ...
- [Angular] Configurable Angular Components - Content Projection and Input Templates
We are going to have a modal component: <au-modal > </au-modal> And we can pass default ...
- [WASM] Call a JavaScript Function from WebAssembly
Using WASM Fiddle, we show how to write a simple number logger function that calls a consoleLog func ...
- DateTime与timeStamp的转换
DateTime转换为timeStamp: DateTime dt = DateTime.Now; DateTime startTime = TimeZone.CurrentTi ...
- 洛谷 P3871 中位数
->题目链接 题解: 暴力 经鉴定,此题数据水到没朋友. #include<algorithm> #include<iostream> #include<cstdi ...