码迷,mamicode.com
首页 > 其他好文 > 详细

CF #367 DIV2 E

时间:2016-08-15 20:34:09      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

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

#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;
}

  

CF #367 DIV2 E

标签:

原文地址:http://www.cnblogs.com/jie-dcai/p/5774153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!