UVa 11040 - Add bricks in the wall

纯粹找规律的一小学数学题,空格处的数可有输入计算得出,每个6格三角形为一个计算单位。

#include <iostream>
#include <cstdio>
using namespace std;

int tab[10][10];

int main()
{
	int T; cin >> T;
	while (T--){
		for (int i = 0; i <= 8; i += 2) for (int j = 0; j <= i; j += 2)
			cin >> tab[i][j];
		for (int i = 0; i <= 6; i += 2) for (int j = 0; j <= i; j += 2){
			int a = tab[i][j], b = tab[i + 2][j], c = tab[i + 2][j + 2];
			tab[i + 1][j] = (a + b - c) / 2;
			tab[i + 1][j + 1] = (a - b + c) / 2;
			tab[i + 2][j + 1] = (a - b - c) / 2;
		}
		for (int i = 0; i <= 8; ++i) for (int j = 0; j <= i; j++)
			printf("%d%c", tab[i][j], j == i ? '\n' : ' ');
	}
	return 0;
}


posted @ 2015-03-03 13:25  Popco  阅读(186)  评论(0编辑  收藏  举报