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 ...
随机推荐
- Problem J: 搜索基础之红与黑
Problem J: 搜索基础之红与黑 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 170 Solved: 100[Submit][Status][ ...
- Maven父子模块引入依赖问题
公共模块如何放到父pom中,而子pom无需再次引入???
- PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)
http://www.patest.cn/contests/pat-a-practise/1092 Eva would like to make a string of beads with her ...
- C#装箱与拆箱的研究
在对这个问题展开讨论之前,我们不妨先来问这么几个问题,以系统的了解我们今天要探究的主题. 观者也许曾无数次的使用过诸如System.Console类或.NET类库中那些品种繁多的类.那么,我想问的是它 ...
- 第十三篇、OC_UICollectionView的基本配置
- (UICollectionView *) categoryCollectionView { if (! _categoryCollectionView) { // 创建布局 UICollectio ...
- vue学习之路 - 2.基本操作(上)
基本操作(上) 本章节简介: vue的安装 vue实例创建 数据绑定渲染 表单数据双向绑定 事件处理 安装 安装方式有三种: 一.vue官网直接下载 http://vuejs.org/js/vue.m ...
- python用requests请求,报SSL:CERTIFICATE_VERIFY_FAILED错误。
response = requests.request("GET", url, headers=headers, params=querystring, verify=False) ...
- PHP 工厂模式介绍
工厂模式,顾名思义,如同工厂一样,你把原材料放入工厂中,出来的是成品,而你并不需要知道工厂里做了什么.代码中也类似,把主要参数放入一个工厂里,返回的是处理好的数据,我们并不需要工厂里做了什么,只需要知 ...
- tp3.2框架中使用volist输出混乱的一点发现
在tp框架中,volist真的是一样很好用的东西,但是要是不注意,用起来也会有问题的 在Controller层中,将数据assign到页面 $this->assign('vo',$news); ...
- 服务端Latex解析成图片或者HTML或者SVG方案
Latex公式表达式在服务端进行转换成可用数据 使用语言与扩展 node.js Mathjax (文档链接) MathJax在nodejs上解决方案 mathjax/MathJax-node(GitH ...