CF #367 DIV2 E

直接使用指针,交换时交换矩阵周围的指针即可。

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 1005;

struct dl{
	int v;
	struct dl *d, *r;
}e[N][N];

int main(){
	int n, m , q;
	scanf("%d%d%d", &n, &m, &q);
	int x, y, s, t, h, w;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++)
			scanf("%d", &e[i][j].v);
	}

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			e[i][j].r = &e[i][j + 1];
			e[i][j].d = &e[i + 1][j];
		}
	}

	for(int i = 1; i <= q; i++){
		scanf("%d%d%d%d%d%d", &x, &y, &s, &t, &h, &w);
		dl *pos1, *pos2;
		pos2 = pos1 = &e[0][0];
		int th = h, tw = w;
		while(-- x) pos1 = pos1 -> d;
		while(-- y) pos1 = pos1 -> r;
		th = h, tw = w;
		while(-- s) pos2 = pos2 -> d;
		while(-- t) pos2 = pos2 -> r;

		dl* tp1 = pos1, *tp2 = pos2;

		for(int r = 1; r <= h; r++){
			pos1 = pos1 -> d;
			pos2 = pos2 -> d;
			swap(pos1 -> r, pos2 -> r);
		}

		for(int c = 1; c <= w; c++){
			pos1 = pos1 -> r;
			pos2 = pos2 -> r;
			swap(pos1 -> d, pos2 -> d);
		}

		for(int c = 1; c <= w; c++){
			tp1 = tp1 -> r;
			tp2 = tp2 -> r;
			swap(tp1 -> d, tp2 -> d);
		}

		for(int r = 1; r <= h; r ++){
			tp1 = tp1 -> d;
			tp2 = tp2 -> d;
			swap(tp1 -> r, tp2 -> r);
		}
	}

	dl *pos1 = &e[0][0];

	for(int i = 1; i <= n; i++){
		pos1 = pos1 -> d;
		dl *tmp = pos1;
		for(int j = 1; j <= m; j++){
			pos1 = pos1 ->r;
			if(j == 1)
			printf("%d", pos1 ->v);
			else printf(" %d", pos1 ->v);
		}
		puts("");
		pos1= tmp;
	}

	return 0;
}

  

时间: 2024-10-07 16:28:38

CF #367 DIV2 E的相关文章

CF #261 div2 D. Pashmak and Parmida&amp;#39;s problem (树状数组版)

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence a that consists of n

CF #261 DIV2 A,B,C,D

A 先判断邻边长度是否相等,不是就无法构成正方形,否则的话位置坐标搞一下 #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <bitset> #include <vector> #include <set>

CF#215 DIV2: B. Sereja and Suffixes

Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1,?l2,?...,?lm (1?≤?li?≤?n). For each number li he wants to know

cf#261 div2 解题报告

.....代码没什么可说的,主要是学习各路大神姿势 A题 化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错 ........和最优代码相比姿势有点混乱 #include <cstdio> int x[4],y[4]; int abs(int n){ return n<0?-n:n; } int main(){ scanf("%d%d%d%d",x,y,x+1,y+1); int dx=abs(x[0]-x[1]); int dy=abs

cf 301 div2

A - Combination Lock 题目大意:给有n个(0-9)环圈密码锁,数串 s1->s2最少移动次数: 题目分析: 简单模拟: 代码: const int N=100007; char s1[N],s2[N]; int main() { int n; while(scanf("%d",&n)==1) { int ans=0; scanf("%s%s",s1+1,s2+1); for(int i=1;i<=n;i++) { int a=

CF R631 div2 1330 E Drazil Likes Heap

LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了一下就没了. 但是到E就只剩下30min(都怪A B浪费我过多时间. 观察题目中给的一个程序 其维护了一个大根堆且这个程序意思是一个函数 这个函数是指对于这个大根堆上的一个非空节点来说每次会将这个值给删掉继承最大的儿子值 然后递归值最大的儿子值得某个节点没有一个非空儿子(那么这个点的值被删掉为0.

CF 313 DIV2 B 树状数组

http://codeforces.com/contest/313/problem/B 题目大意 给一个区间,问你这个区间里面有几个连续相同的字符. 思路: 表示个人用树状数组来写的...了解了树状数组的本质就行了. 当然用sum[r]-sum[l]也是可以的

CF #327 DIV2 D、E

两题都不难. 对于D题,可以使用相对移动,把吹aircraft移动变成相反方向的待援点的移动.假设此时时间为t,把aircraft的速度设为Vmax,看待援点在飞船最大速度飞行t秒的范围内,注意风向变化的时间点即可.其实很明显的二分.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 6 using namespace std; 7

CF R274 Div2 E Riding in a Lift DP

先预处理出能到当前点的区间,然后通过前缀和求得当前值即可. #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <stack> #include <map> #include <set> #include <climits> #include <iostream> #include &