7月6日 Add bricks in the wall

Add bricks in the wall

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n = 0; // 测试用例数量
  int t = 9; // 行数
  cin >> n;

  while (n--) {
    int triangle[46];
    for (int i = 1; i <= 9; i += 2) {
      for (int j = 1; j <= i; j += 2) {
        cin >> triangle[((i - 1) * i) / 2 + j];
      }
    }

    for (int i = 3; i <= 9; i += 2) {
      for (int j = 2; j <= i; j += 2) {
        triangle[((i - 1) * i) / 2 + j] =
            (triangle[((i - 3) * (i - 2)) / 2 + j - 1] -
             triangle[((i - 1) * i) / 2 + j - 1] -
             triangle[((i - 1) * i) / 2 + j + 1]) /
            2;
      }
    }

    for (int i = 2; i <= 9; i += 2) {
      for (int j = 1; j <= i; j++) {
        triangle[((i - 1) * i) / 2 + j] = triangle[((i + 1) * i) / 2 + j] +
                                          triangle[((i + 1) * i) / 2 + j + 1];
      }
    }
    for(int i = 1; i <= 9; i++){
      for(int j = 1; j < i; j++){
        cout << triangle[((i - 1) * i) / 2 + j] << " ";
      }
      cout << triangle[((i - 1) * i) / 2 + i] << endl;
    }
  }
  return 0;
}

posted @ 2023-08-24 16:27  tlocd  阅读(12)  评论(0编辑  收藏  举报