JZOJ 5281 钦点

样例输入:
4 4 2
a a b b
a a b b
c c d d
c c d d
1 1 3 3 2 2
3 1 1 3 2 2
样例输出:
d d c c
d d c c
b b a a
b b a a
思路:
既然是在矩形里面操作,而且每次移动的是一个整块,同时移动的一对矩形不会相邻
那么就使用一个四向链表模拟矩形,保存每个节点的上下左右节点
实际使用时发现其实双向(向下和向右)就够了
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<string>
using namespace std;
int n,m,q;
struct point{
string v;
int r,d;
}ma[];
int trans(int x,int y){
return y*(m+)+x;
}
int pos(int x,int y){
if (x>y){
int ans=trans(x,);
for (int i=;i<y;i++) ans=ma[ans].d;
return ans;
}
else {
int ans=trans(,y);
for (int i=;i<x;i++) ans=ma[ans].r;
return ans;
}
} int main(){
std::ios::sync_with_stdio(false);
cin>>n>>m>>q;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
if (i&&j) cin>>ma[trans(j,i)].v;
ma[trans(j,i)].r=trans(j+,i);
ma[trans(j,i)].d=trans(j,i+);
} while(q--){
int x1,y1,x2,y2,l,c;
cin>>y1>>x1>>y2>>x2>>l>>c;
int p1=pos(x1-,y1-),p2=pos(x2-,y2-);
int t1=p1,t2=p2;
for(int i=;i<=l;i++){
t1=ma[t1].d;t2=ma[t2].d;
swap(ma[t1].r,ma[t2].r);
}
for(int i=;i<=c;i++){
t1=ma[t1].r;t2=ma[t2].r;
swap(ma[t1].d,ma[t2].d);
}
t1=p1,t2=p2;
for(int i=;i<=c;i++){
t1=ma[t1].r;t2=ma[t2].r;
swap(ma[t1].d,ma[t2].d);
}
for(int i=;i<=l;i++){
t1=ma[t1].d;t2=ma[t2].d;
swap(ma[t1].r,ma[t2].r);
}
}
int p=;
for(int i=;i<=n;i++){
p=ma[p].d;
for(int j=,q=p;j<=m;j++){
q=ma[q].r;
cout<<ma[q].v<<" ";
}
cout<<endl;
}
}
JZOJ 5281 钦点的更多相关文章
- JZOJ.5281【NOIP2017模拟8.15】钦点
Description
- hdu 5281 Senior's Gun
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...
- HDU 5281 Senior's Gun (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...
- (jzoj snow的追寻)线段树维护树的直径
jzoj snow的追寻 DFS序上搞 合并暴力和,记录最长链和当前最远点,距离跑LCA # include <stdio.h> # include <stdlib.h> # ...
- [jzoj]3506.【NOIP2013模拟11.4A组】善良的精灵(fairy)(深度优先生成树)
Link https://jzoj.net/senior/#main/show/3506 Description 从前有一个善良的精灵. 一天,一个年轻人B找到她并请他预言他的未来.这个精灵透过他的水 ...
- [jzoj]3468.【NOIP2013模拟联考7】OSU!(osu)
Link https://jzoj.net/senior/#main/show/3468 Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: ...
- [jzoj]5478.【NOIP2017提高组正式赛】列队
Link https://jzoj.net/senior/#main/show/5478 Description Sylvia 是一个热爱学习的女孩子. 前段时间,Sylvia 参加了学校 ...
- [jzoj]1115.【HNOI2008】GT考试
Link https://jzoj.net/senior/#main/show/1115 Description 申准备报名参加GT考试,准考证号为n位数X1X2X3...Xn-1Xn(0<=X ...
- [jzoj]2538.【NOIP2009TG】Hankson 的趣味题
Link https://jzoj.net/senior/#main/show/2538 Description Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫H ...
随机推荐
- MySql学习笔记02
MySql02 复习 数据库相关 连接数据库的命令 mysql -uroot -p 创建数据库 create database db2; 查询所有的数据库 show databases; 查询单个数据 ...
- python 写 组合两两组合
紧挨着 组合 a b c d ----> ab ,bc ,cd portList = ['a', 'b', 'c', 'd'] for i, p in enumerate(portList) ...
- 七、Linux 文件与目录管理
Linux 文件与目录管理 我们知道Linux的目录结构为树状结构,最顶级的目录为根目录 /. 其他目录通过挂载可以将它们添加到树中,通过解除挂载可以移除它们. 在开始本教程前我们需要先知道什么是绝对 ...
- HashMap原理以及自己实现HashMap
1.HashMap是什么? HashMap是java常用来存储键值对的数据结构,它是以key/value的形式存储的,它不是线程安全的,Key可以为null值. 2.HashMap的实现原理 Hash ...
- DevOps - 日志分析 -ELK
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...
- Redis之Hash类型操作
接口IRedisDaoHash: package com.net.test.redis.base.dao; import com.net.test.redis.base.entity.UserPsg; ...
- Pychram基本操作
1. 更改pychram页面为黑色背景主题.更改主题: File ->Settings -> Editor -> Color Scheme -> Scheme -> Mo ...
- [BZOJ1187]神奇游乐园(插头DP)
Description 题意给定一个矩阵,每个格子有权值,在[-1000.1000]内,求一条回路使得回路经过权值和最大,每个格子最多经过一次 2≤n≤100,2≤m≤6 Code #include ...
- U1
如果 activity_main.xml没有xml代码可以对图像右键 go to mxl同时可以在design 和 text 切换 在安装了Android Studio3.3版本之后,第一个He ...
- 查找两个链表的第一个交叉结点(Python实现)
题目 给定两个单链表,查找这两个单链表的第一个交叉节点. 例如:链表list_a为:a1→a2→c1→c2→c3,链表list_b为:b1→b2→b3→c1→c2→c3.那么它们第一个交叉结点为c1. ...