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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
| #include <bits/stdc++.h> #include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";}
using namespace std; using namespace __gnu_pbds;
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>;
const ll MOD = 1000000007; const ll MAX = 1e7;
template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; }
ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; }
ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; }
pii operator+(pii a, pii b){ return mp(a.F + b.F, a.S + b.S); }
pii operator-(pii a, pii b){ return mp(a.F - b.F, a.S - b.S); }
pii operator+=(pii& a, pii b){ return a = a + b; }
pii operator*(pii a, int b){ return mp(a.F * b, a.S * b); }
pii operator-(pii a){ return mp(-a.F, -a.S); }
vector<pii> ans; pii now = mp(0, 0);
void move(pii v, int d){ d %= 4; if(d == 0) now += v; else if(d == 1) now += mp(-v.S, v.F); else if(d == 2) now += -v; else now += mp(v.S, -v.F); ans.eb(now); }
void move(pii to){ ans.eb(to); now = to; }
int type(pii seg){ if(seg.F == 0) return 1; return 0; }
struct block{ int w = 0, h = 0; vector<block*> nxt; void add(block* b){ w += b->h; h += b->w; nxt.eb(b); } };
int lp = 0; string s; block* solve(){ block* b = new block({2, 2}); lp++; while(s[lp] == 'L'){ b->add(solve()); } lp++; return b; }
void draw(block* b, int dir){ move(mp(b->w - 1, 0), dir); move(mp(0, 1), dir); for(block* nxt : b->nxt){ draw(nxt, dir + 1); } move(mp(0, 1), dir); move(mp(b->w - 1, 0), dir); }
int main(){ StarBurstStream;
string t; cin >> t; int n = t.size();
int cnt = 0; for(char i : t){ if(i == 'L') cnt++; else cnt--; }
if(cnt != 4){ cout << "NIE\n"; return 0; }
deque<pii> st; for(int i = 0; i < n; i++){ if(t[i] == 'L'){ st.eb(mp(i, 1)); continue; } if(!st.empty() && st.back().S == 1){ st.pob; continue; } st.eb(mp(i, -1)); } while(st.front().S == -1){ st.pof; st.pob; } for(int i = 0; i < 4; i++){ s.clear(); lp = 0; for(int j = (st[i].F + 1) % n; j != st[(i + 1) % 4].F; j = (j + 1) % n){ s += t[j]; } move(mp(MAX, 0), i); while(lp < s.size()){ block* b = solve(); draw(b, i); } if(i < 3) move(mp(MAX, 0), i); } move(mp(ans.back().F, ans.front().S));
vector<pii> pnt; pnt.eb(ans.back()); for(int i = 0; i + 1 < ans.size(); i++){ while(pnt.size() >= 2 && type(ans[i] - pnt.back()) == type(pnt.back() - pnt[(int)pnt.size() - 2])) pnt.pob; pnt.eb(ans[i]); } while(type(pnt.back() - pnt[(int)pnt.size() - 2]) == type(pnt.back() - pnt.front())) pnt.pob; for(pii i : pnt){ cout << i.F << " " << i.S << "\n"; }
return 0; }
|