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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include<bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std;
const int maxn=40005;
int n,f[8][8]; vector<int> a;
void Move(int x1,int y1,int x2,int y2,int num) { fo(i,x1,x2-1) printf("%d %d D %d\n",i,y1,num); fo(j,y1,y2-1) printf("%d %d R %d\n",x2,j,num); }
void dfs(int x,int y,vector<int> a,int l,int r) { if (x==6 && y==6) return; if (x+y==11) { if (a.size()==1) Move(x,y,6,6,1); else { if (a[0]>a[1]) Move(x,y,6,6,2); else Move(x,y,6,6,1), Move(x,y,6,6,1); } return; } vector<int> ned[7][7]; int lo[7][7],hi[7][7]; int now=r; fd(i,6,x) { fd(j,6,y) { lo[i][j]=max(l,now-f[i][j]+1); hi[i][j]=now; now-=hi[i][j]-lo[i][j]+1; ned[i][j].clear(); if (now<l) break; } if (now<l) break; } for(int k=a.size()-1; k>=0; k--) { int e=a[k]; bool pd=0; fd(i,6,x) { fd(j,6,y) if (lo[i][j]<=e && e<=hi[i][j]) { ned[i][j].push_back(e); Move(x,y,i,j,1); pd=1; break; } if (pd) break; } } now=r; fd(i,6,x) { fd(j,6,y) { dfs(i,j,ned[i][j],lo[i][j],hi[i][j]); now-=hi[i][j]-lo[i][j]+1; if (now<l) break; } if (now<l) break; } }
int main() { scanf("%d",&n); fo(i,1,n) { int x; scanf("%d",&x); a.push_back(x); } f[6][6]=1; f[5][6]=f[6][5]=2; f[5][5]=5; fd(i,6,1) fd(j,6,1) if (i<5 || j<5) fo(x,i,6) fo(y,j,6) f[i][j]+=f[x][y]; dfs(1,1,a,1,n); }
|