十字链表 Codeforces Round #367 E Working routine

 1 // 十字链表 Codeforces Round #367 E Working routine
 2 // 题意:给你一个矩阵,q次询问,每次交换两个子矩阵,问最后的矩阵
 3 // 思路:暴力肯定不行。我们可以每个元素建立十字链表,记录右边和下边的元素,和每个元素的下标(从0开始),每次询问只需要交换四条边的指向即可。
 4 // 本题要建立(n+1)*(m+1)的矩阵
 5
 6 #include <bits/stdc++.h>
 7 using namespace std;
 8 #define LL long long
 9 const double inf = 123456789012345.0;
10 const LL MOD =100000000LL;
11 const int N =1010*1010;
12 #define clc(a,b) memset(a,b,sizeof(a))
13 const double eps = 1e-7;
14 void fre() {freopen("in.txt","r",stdin);}
15 void freout() {freopen("out.txt","w",stdout);}
16 inline int read() {int x=0,f=1;char ch=getchar();while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1; ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘) {x=x*10+ch-‘0‘;ch=getchar();}return x*f;}
17
18 int n,m,q;
19 struct node{
20     int v,r,d;
21 }a[N];
22
23 int chg(int y,int x){
24     return y*(m+1)+x;
25 }
26
27 int main(){
28     scanf("%d%d%d",&n,&m,&q);
29     for(int i=1;i<=n;i++){
30         for(int j=1;j<=m;j++){
31             scanf("%d",&a[chg(i,j)].v);
32         }
33     }
34
35     for(int i=0;i<=n;i++){
36         for(int j=0;j<=m;j++){
37             a[chg(i,j)].r=chg(i,j+1);
38             a[chg(i,j)].d=chg(i+1,j);
39         }
40     }
41     while(q--){
42         int x1,y1,x2,y2,h,w;
43         scanf("%d%d%d%d%d%d",&y1,&x1,&y2,&x2,&h,&w);
44         int p1=0,p2=0;
45         for(int i=1;i<y1;i++) p1=a[p1].d;
46         for(int i=1;i<x1;i++) p1=a[p1].r;
47         for(int i=1;i<y2;i++) p2=a[p2].d;
48         for(int i=1;i<x2;i++) p2=a[p2].r;
49         int t1=p1;
50         int t2=p2;
51         for(int i=1;i<=h;i++){
52             t1=a[t1].d;
53             t2=a[t2].d;
54             swap(a[t1].r,a[t2].r);
55         }
56         for(int i=1;i<=w;i++){
57             t1=a[t1].r;
58             t2=a[t2].r;
59             swap(a[t1].d,a[t2].d);
60         }
61         t1=p1,t2=p2;
62         for(int i=1;i<=w;i++){
63             t1=a[t1].r;
64             t2=a[t2].r;
65             swap(a[t1].d,a[t2].d);
66         }
67         for(int i=1;i<=h;i++){
68             t1=a[t1].d;
69             t2=a[t2].d;
70             swap(a[t1].r,a[t2].r);
71         }
72     }
73     int p=0;
74     for(int i=1;i<=n;i++){
75         p=a[p].d;
76         int q=p;
77         for(int j=1;j<=m;j++){
78             q=a[q].r;
79             printf("%d ",a[q].v);
80         }
81         printf("\n");
82     }
83     return 0;
84 }
时间: 2024-07-30 23:56:32

十字链表 Codeforces Round #367 E Working routine的相关文章

Codeforces Round #367 (Div. 2) D. Vasiliy&#39;s Multiset

题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 题解: trie树xjb搞就行,每次要贪心,尽量满足高位为1. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;i++) 3 using namespace std; 4 5 namespace trie 6 {

trie树 Codeforces Round #367 D Vasiliy&#39;s Multiset

1 // trie树 Codeforces Round #367 D Vasiliy's Multiset 2 // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 3 // 思路:思路很好想,建立trie树,再贪心当前位是1则选0,0则选1 4 5 6 #include <bits/stdc++.h> 7 using namespace std; 8 #define LL long long 9 const double inf = 123456789

Codeforces Round #367 (Div. 2) 套题

吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string>

Codeforces Round #367 (Div. 2)

A. Beru-taxi (Codeforces 706A) 水题,求一下到每个点的距离,取最小值即可 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define N using namespace std; int n,x,y,p,q,s; double t,ans=1000000000; int main() { scanf("%d%d%d&

Codeforces Round #367 Div. 2 [11110]

#include <iostream> #include <map> #include <math.h> using namespace std; int main() { double a, b; cin >> a >> b; int n; cin >> n; double MIN = 1e10; while (n--) { double x, y, v; cin >> x >> y >> v;

Codeforces Round #367 (Div. 2) 题解

A code: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #define maxn 1005 using namespace std; int main() { double ans,tans; double x0,y0,x,y,v; cin >> x0 >> y0; ans

Codeforces Round #367 (Div. 2) ABCD

A. Beru-taxi 题解: 水,求下距离就行了 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define ll long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #

Codeforces Round #196 (Div. 2) B. Routine Problem

screen 尺寸为a:b video 尺寸为 c:d 如果a == c 则 面积比为 cd/ab=ad/cb (ad < cb) 如果b == d 则 面积比为 cd/ab=cb/ad  (cb < ad) 如果不相等时 如果a/b > c/d,则ad/bd > cb/db 则(ad > cb) screen尺寸可为 ad:bd, video的尺寸可为 cb:db 面积比为:cb*db/ad*bd = cb/ad (ad > cb) 如果a/b < c/d,则a

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/