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 ...
随机推荐
- Java中ArrayList的对象引用问题
前言事件起因是由于同事使用ArrayList的带参构造方法进行ArrayList对象复制,修改新的ArrayList对象中的元素(对象)的成员变量时也会修改原ArrayList中的元素(对象)的成员变 ...
- numpy各函数简介之生成数组函数
1.empty(shape[, dtype, order]) 依据给定形状和类型(shape[, dtype, order])返回一个新的空数组. 参数: shape : 整数或者整型元组 定义返回数 ...
- 纯js实现淘宝商城轮播图
需求: 循环无缝自动轮播3张图片,点击左右箭头可以手动切换图片,鼠标点击轮播图下面的小圆点会跳转到对应的第几张图片.鼠标放到轮播图的图片上时不再自动轮播,鼠标移开之后又继续轮播.效果图: 下面是htm ...
- javaweb基础(28)_jstl的核心标签
一.JSTL标签库介绍 JSTL标签库的使用是为弥补html标签的不足,规范自定义标签的使用而诞生的.使用JSLT标签的目的就是不希望在jsp页面中出现java逻辑代码 二.JSTL标签库的分类 核心 ...
- Websocket教程SpringBoot+Maven整合(详情)
1.大话websocket及课程介绍 简介: websocket介绍.使用场景分享.学习课程需要什么基础 笔记: websocket介绍: WebSocket协议是基于TCP的一种新的网络协议.它实现 ...
- Django 模型与 Mysql 数据类型对应
Django 1.11.9 文件路径:site-packages\django\db\backends\mysql\base.py–class DatabaseWrapper _data_types ...
- python 基础 for else
for one in many_list: if "k" in one: print "在里面" break else: print "没有在里面&q ...
- DNS服务初步搭建
一.准备DNS服务环境 选择 bind dns服务软件包 直接yum安装 bind 和 bind-utils 工具包,测试机器安装bind-utils测试工具包. 服务程序名为 named 二.配置D ...
- 配置vim nginx.conf高亮
#!/bin/bashwget http://www.vim.org/scripts/download_script.php?src_id=14376 -O nginx.vimmv nginx.vim ...
- oracle 11gR2 for win7旗舰版64安装以及连接plsql和NaviCat(win64_11gR2_database) (2012-12-31-bd 写的日志迁移
先到oracle官网http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html下载必要数 ...