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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <istream> #include <map> #include <cmath> #include <stack> #include <set> #include <cstring> #include <string> #define ll long long #define maxn 200005 #define mdl 1000000007 #define clr(a,n) for(int i=0;i<n;i++)a[i]=0 #define cfast std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pll pair<ll,ll> #define inc(i,a,n) for(ll i=a;i<n;i++) #define vset(a,n,m) for(ll i=0;i<n;i++)a[i]=m; using namespace std; struct node { ll a, b, c, d; }; ll dp[4][4][205][205]; map<ll, node> rcd[4][4][205]; void ddp() { dp[0][0][0][0] = 1; inc(x, 0, 4) { inc(y, 0, 4) { if (x == 3 && y == 3)break; inc(i, 0, 201) { inc(j, 0, 201) { int cst = 25; if (x +y==5)cst = 15; if (y > 0&&x!=3) { inc(k, 0, i + 1) { if (j < cst)break; if (k >= cst-1)break; if (dp[x][y - 1][i - k][j - cst] == 1) { dp[x][y][i][j] = 1; node xx = { x,y - 1,i - k,j - cst }; rcd[x][y][i][j] = xx; } } inc(k, cst+1, 201) { if (i - k + 2 < 0 || j - k < 0)break; if (dp[x][y - 1][i - k + 2][j - k] == 1) { dp[x][y][i][j] = 1; node xx = { x,y - 1,i - k + 2,j - k }; rcd[x][y][i][j] = xx; } } } if (x > 0&&y!=3) { inc(k, 0, j + 1) { if (i < cst)break; if (k >= cst-1)break; if (dp[x - 1][y][i - cst][j - k] == 1) { dp[x][y][i][j] = 1; node xx = { x - 1,y,i - cst,j - k }; rcd[x][y][i][j] = xx; } } inc(k, cst+1, 201) { if (i - k < 0 || j - k + 2 < 0)break; if (dp[x - 1][y][i - k][j - k + 2] == 1) { dp[x][y][i][j] = 1; node xx = { x - 1,y,i - k,j - k + 2 }; rcd[x][y][i][j] = xx; } } } } } } } } stack < pll> ans; int main() { cfast; ddp(); int m; cin >> m; while (m--) { int c1=0, c2=0; int a, b; cin >> a >> b; if (dp[3][0][a][b] == 1)c1 = 3, c2 = 0; else if (dp[3][1][a][b] == 1)c1 = 3, c2 = 1; else if (dp[3][2][a][b] == 1)c1 = 3, c2 = 2; else if (dp[2][3][a][b] == 1)c1 = 2, c2 = 3; else if (dp[1][3][a][b] == 1)c1 = 1, c2 = 3; else if (dp[0][3][a][b] == 1)c1 = 0, c2 = 3; else cout << "Impossible" << endl; if (c1 + c2 > 0) { cout << c1 << ":" << c2 << endl; } while (c1 + c2 > 0) { node xx = rcd[c1][c2][a][b]; pll p; p.first = a - xx.c, p.second = b - xx.d; ans.push(p); c1 = xx.a, c2 = xx.b, a = xx.c, b = xx.d; } while (ans.size()) { cout << ans.top().first << ":" << ans.top().second << " "; if(ans.size()==1)cout << endl; ans.pop(); } } }
|