#include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; string duplicate_command(string s, ll n){ if (n==0) return ""; if (n==1) return s; if (n<10) return to_string(n)+'['+s+']'; if (n%9==0) return "9["+duplicate_command(s, n/9)+"]"; if (n%9==1) return s+to_string(9)+'['+duplicate_command(s, n/9)+']'; return to_string(n%9)+'['+s+']'+to_string(9)+'['+duplicate_command(s, n/9)+']'; } string generate_romb(ll n){ ll x = (n+1)/2; ll y = n-x; string res = duplicate_command(duplicate_command("AE", x)+'A'+duplicate_command("C", x), y); return res; } string generate_traingle(ll n){ if (n <= 0) return ""; if (n == 1) return "AEC"; if (n == 2) return "2A2ECACEC"; if (n==3) return "3F3BD2E2[AC]DFDBD"; string res = generate_romb(n); res += duplicate_command("A", (n+1)/2); if (n%2==1) res += 'E'+duplicate_command("CE", n/2)+duplicate_command("A", n/2); res += "2["; res += 'E'+duplicate_command("CE", n/2-1)+'A'; res += generate_traingle(n/2-2)+duplicate_command("EA", n/2 - 2)+"E"; res += ']'; res += duplicate_command("C", n); return res; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); ll n; cin >> n; string ans = generate_traingle(n); //cout << ans.size() << "\n"; cout << ans << "\n"; }
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 | #include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; string duplicate_command(string s, ll n){ if (n==0) return ""; if (n==1) return s; if (n<10) return to_string(n)+'['+s+']'; if (n%9==0) return "9["+duplicate_command(s, n/9)+"]"; if (n%9==1) return s+to_string(9)+'['+duplicate_command(s, n/9)+']'; return to_string(n%9)+'['+s+']'+to_string(9)+'['+duplicate_command(s, n/9)+']'; } string generate_romb(ll n){ ll x = (n+1)/2; ll y = n-x; string res = duplicate_command(duplicate_command("AE", x)+'A'+duplicate_command("C", x), y); return res; } string generate_traingle(ll n){ if (n <= 0) return ""; if (n == 1) return "AEC"; if (n == 2) return "2A2ECACEC"; if (n==3) return "3F3BD2E2[AC]DFDBD"; string res = generate_romb(n); res += duplicate_command("A", (n+1)/2); if (n%2==1) res += 'E'+duplicate_command("CE", n/2)+duplicate_command("A", n/2); res += "2["; res += 'E'+duplicate_command("CE", n/2-1)+'A'; res += generate_traingle(n/2-2)+duplicate_command("EA", n/2 - 2)+"E"; res += ']'; res += duplicate_command("C", n); return res; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); ll n; cin >> n; string ans = generate_traingle(n); //cout << ans.size() << "\n"; cout << ans << "\n"; } |