zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    [Codeforces 140C] New Year Snowmen
    [Codeforces Round511C] Enlarge GCD
    [BZOJ 1251] 序列终结者
    [NOIP 2016] 愤怒的小鸟
    [POJ 1860] Currency Exchange
    [ZJOI 2006] 书架
    [NOIP 2010] 引入入城
    [NOI 2014] 起床困难综合征
    用C语言实现中文到unicode码的转换
    strdup与strndup
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/5774153.html
Copyright © 2011-2022 走看看