SHARE
TWEET

Untitled

a guest May 19th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. class Tree {
  8. public:
  9.     size_t topPos;
  10.     size_t height;
  11.     size_t triangles;
  12. };
  13.  
  14.  
  15. void print(Tree& tree, vector<string>& image, vector<Tree>& trees) {
  16.     if (tree.height > image.size()) {
  17.         size_t size = image.size();
  18.         for (int i = 0; i < tree.height - size; ++i) {
  19.             string newStr;
  20.             newStr.assign(image[0].size(), '.');
  21.             image.push_back(newStr);
  22.         }
  23.     }
  24.  
  25.     size_t new_top = trees.back().topPos + trees.back().height + trees.back().triangles - 1;
  26.     bool flag = true;
  27.  
  28.     while (flag) {
  29.         flag = false;
  30.         for (size_t i = tree.triangles; i >= 0; --i) {
  31.             size_t height = (i + 1) * tree.height + i * (i + 1) / 2 - 1;
  32.  
  33.             if ((height < image.size()) && (new_top - tree.height - i < image[0].size()) &&
  34.                 (image[height][new_top - tree.height - i] == '#') ||
  35.                 (height + 1 < image.size()) && (image[0].size() > new_top - tree.height  - i) &&
  36.                 image[height][new_top - tree.height - i] == '#' ||
  37.                 (height - 1 > 0) && (height - 1 < image.size()) &&
  38.                 (image[0].size() > new_top - tree.height - i) &&
  39.                 image[height][new_top - tree.height - i] == '#') {
  40.                 flag = true;
  41.                 ++new_top;
  42.                 break;
  43.             }
  44.         }
  45.     }
  46.  
  47.     tree.topPos = new_top;
  48.     if (new_top + tree.height - 1 + tree.triangles >= image[0].size()) {
  49.         string dop;
  50.         dop.assign(new_top + tree.height + tree.triangles - image[0].size() - 1, '.');
  51.  
  52.         size_t imageSize = image.size();
  53.         for (size_t i = 0; i < imageSize; ++i) {
  54.             image[i] += dop;
  55.         }
  56.     }
  57.  
  58.     for (size_t i = 0; i < tree.triangles; ++i) {
  59.         size_t start = i * tree.height + (i * (i - 1)) / 2;
  60.  
  61.         for (size_t j = 0; j < tree.height + i; ++j) {
  62.             for (int k = 0; k <= j; ++k) {
  63.                 image[start + j][new_top + k] = '#';
  64.                 image[start + j][new_top - k] = '#';
  65.             }
  66.         }
  67.     }
  68.  
  69.     trees.push_back(tree);
  70. }
  71.  
  72. int main() {
  73.     int queries;
  74.     cin >> queries;
  75.  
  76.     Tree tree;
  77.  
  78.     cin >> tree.triangles >> tree.height;
  79.  
  80.     tree.topPos = tree.height + tree.triangles - 2;
  81.  
  82.     vector<Tree> trees;
  83.     trees.push_back(tree);
  84.  
  85.  
  86.     vector<string> image;
  87.  
  88.     string str;
  89.     str.assign(tree.topPos + tree.height + tree.triangles - 1 , '.');
  90.  
  91.     for (size_t i = 0; i < tree.height * tree.triangles +
  92.         (tree.triangles * (tree.triangles - 1)) / 2; ++i) {
  93.         image.push_back(str);
  94.     }
  95.  
  96.     for (size_t i = 0; i < tree.triangles; ++i) {
  97.         size_t start = i * tree.height + (i * (i - 1)) / 2;
  98.  
  99.         for (size_t j = 0; j < tree.height + i; ++j) {
  100.             for (size_t k = 0; k <= j; ++k) {
  101.                 image[start + j][tree.topPos + k] = '#';
  102.                 image[start + j][tree.topPos - k] = '#';
  103.             }
  104.         }
  105.  
  106.     }
  107.  
  108.     for (size_t i = 1; i < queries; ++i) {
  109.         cin >> tree.triangles >> tree.height;
  110.         print(tree, image, trees);
  111.     }
  112.  
  113.     size_t imageSize = image.size();
  114.     for (size_t i = 0; i < imageSize; ++i) {
  115.         cout << image[i] << endl;
  116.     }
  117.  
  118.     return 0;
  119. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top