-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE.cpp
62 lines (55 loc) · 1.8 KB
/
E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 50+5;
struct Node{
int x,y,id;
}a[MAXN],b[MAXN];
int n,m;
std::vector<std::pair<P,P> > S[3];
inline bool cmp1(const Node &a,const Node &b){
return a.x < b.x;
}
inline bool cmp2(const Node &a,const Node &b){
return a.id < b.id;
}
inline void work(Node a[],int o){
FOR(i,1,m) while(a[i].x > i) S[o].pb(MP(MP(a[i].x,a[i].y),MP(a[i].x-1,a[i].y))),a[i].x--;
ROF(i,m,1) while(a[i].x < i) S[o].pb(MP(MP(a[i].x,a[i].y),MP(a[i].x+1,a[i].y))),a[i].x++;
FOR(i,1,m) while(a[i].y > a[i].id) S[o].pb(MP(MP(a[i].x,a[i].y),MP(a[i].x,a[i].y-1))),a[i].y--;
ROF(i,m,1) while(a[i].y < a[i].id) S[o].pb(MP(MP(a[i].x,a[i].y),MP(a[i].x,a[i].y+1))),a[i].y++;
}
int main(){
scanf("%d%d",&n,&m);
FOR(i,1,m){
scanf("%d%d",&a[i].x,&a[i].y);
a[i].id = i;
}
FOR(i,1,m){
scanf("%d%d",&b[i].x,&b[i].y);
b[i].id = i;
}
std::sort(a+1,a+m+1,cmp1);std::sort(b+1,b+m+1,cmp1);
work(a,0);work(b,2);
std::sort(a+1,a+m+1,cmp2);std::sort(b+1,b+m+1,cmp2);
FOR(i,1,m){
while(a[i].x < b[i].x) S[1].pb(MP(MP(a[i].x,a[i].y),MP(a[i].x+1,a[i].y))),a[i].x++;
while(a[i].x > b[i].x) S[1].pb(MP(MP(a[i].x,a[i].y),MP(a[i].x-1,a[i].y))),a[i].x--;
}
printf("%d\n",(int)S[0].size()+S[1].size()+S[2].size());
for(auto &x:S[2]) std::swap(x.fi,x.se);
std::reverse(all(S[2]));
FOR(i,0,2) for(auto x:S[i]) printf("%d %d %d %d\n",x.fi.fi,x.fi.se,x.se.fi,x.se.se);
return 0;
}