UVA 11040 Add bricks in the wall

This in not “another brick in the wall”, it’s just a matter of adding numbers. Suppose you have a wall
with the shape of a triangle, like the one shown below. The wall has 9 rows and row i has exactly i
bricks, considering that top row is the first one and bottom row is the ninth. Some bricks are labeled
with a number and other ones are blank. Notice that labeled bricks appear only on odd rows and they
occupy odd positions within the row. The problem you must solve is finding a suitable number for
each blank brick taking into account one simple rule: the number of a brick is obtained by adding the
numbers of the two bricks below it. Obviously, this rule does not apply to the ninth row. Numbers are
supposed to be integers.
Input
The first line of the input contains an integer N, indicating the number of test cases. This line is
followed by the lines corresponding to the test cases. Each test case is described in five lines. These
five lines correspond to odd rows of the wall, from top to bottom, as described above. Line i contains
the numbers corresponding to odd bricks on row i of the wall (that is, non blank bricks), enumerated
from left to right and separated with a single space. It is supposed that each test case is correct, that
is, there exists a solution to the problem that the case describes.
Output
For each test case, the output should consist of nine lines describing the numbers of all bricks of the wall.
So, line i should contain the numbers corresponding to the i bricks on row i of the wall, enumerated
from left to right and separated by a single space.
Note: Here we have an example with two test cases. The first one corresponds to the wall depicted
above.
Sample Input
2
255
54 67
10 18 13
3 3 5 2
2 1 2 1 1
256
64 64
16 16 16
4 4 4 4
1 1 1 1 1
Sample Output
255
121 134
54 67 67
23 31 36 31
10 13 18 18 13
5 5 8 10 8 5
3 2 3 5 5 3 2
2 1 1 2 3 2 1 1
2 0 1 0 2 1 1 0 1
256
128 128
64 64 64
32 32 32 32
16 16 16 16 16
8 8 8 8 8 8
4 4 4 4 4 4 4
2 2 2 2 2 2 2 2

1 1 1 1 1 1 1 1 1

#include<iostream>
using namespace std;

int a[9][9];

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        for(int i=0;i<9;i++,i++)
        {
            for(int j=0;j<=i;j++,j++)
            {
                cin>>a[i][j];
                //cout<<i<<j;
            }
        }
        a[8][1]=(a[6][0]-a[8][0]-a[8][2])/2;
        a[8][3]=(a[6][2]-a[8][2]-a[8][4])/2;
        a[8][5]=(a[6][4]-a[8][4]-a[8][6])/2;
        a[8][7]=(a[6][6]-a[8][6]-a[8][8])/2;
        for(int i=7;i>=0;i--)
        {
            for(int j=i;j>=0;j--)
            {
                a[i][j]=a[i+1][j]+a[i+1][j+1];
            }
        }
        for(int i=0;i<9;i++)
        {
            cout<<a[i][0];
            for(int j=1;j<=i;j++)
            {
                cout<<" "<<a[i][j];
            }
            cout<<endl;
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值