Advertisement
Tarche

TheAllMightyH

Sep 14th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. //Programming Magic Here. Works in O(n^4). Could be optimized with DP.
  6. vector<string> getH(int n) {
  7.     int size = (int)pow(5, n);
  8.     vector<string> ans(size, string(size, ' '));
  9.     if (n == 1) {
  10.         return {
  11.             "H   H",
  12.             "H   H",
  13.             "HHHHH",
  14.             "H   H",
  15.             "H   H"
  16.         };
  17.     }
  18.     vector<string> smallerH = getH(n - 1);
  19.     int smallerSize = size / 5;
  20.     for (int i = 0; i < 5; i++) {
  21.         for (int j = 0; j < 5; j++) {
  22.             if (j == 0 || j == 4 || i == 2) {
  23.                 for (int a = 0; a < smallerSize; a++) {
  24.                     for (int b = 0; b < smallerSize; b++) {
  25.                         ans[i * smallerSize + a][j * smallerSize + b] = smallerH[a][b];
  26.                     }
  27.                 }
  28.             }
  29.         }
  30.     }
  31.     return ans;
  32. }
  33.  
  34. int main() {
  35.     //Input
  36.     int n;
  37.     cin >> n;
  38.     auto ans = getH(n);
  39.     //Output
  40.     for (auto a : ans) cout << a << '\n';
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement