UVA-11040-Add bricks in the wall (regular, recursive)

Source: Internet
Author: User

Because the number of rows and columns in this arrangement have been fixed, it is better to find the rule. The complete number arrangement of the bottom row and the last three rows can be obtained from the bottom row, so the entire arrangement can be rolled out, my uugly code (I didn't use the last few rows of data in the question ):

#include<stdio.h>#include<iostream>#include<math.h>using namespace std;int main(){    int n;cin>>n;    while(n--)    {        int temp,temp1,temp2,temp3,temp4,zhuan[10][10];        int a,b,c,d,e,f,g,h,i;        cin>>temp;cin>>temp;cin>>temp;        cin>>temp;cin>>temp;cin>>temp;        cin>>temp1;cin>>temp2;cin>>temp3;        cin>>temp4;        cin>>a>>c>>e>>g>>i;        b = (temp1 - a - c) / 2;        d = (temp2 - e - c) / 2;        f = (temp3 - e - g) / 2;        h = (temp4 - g - i) / 2;        zhuan[0][0] = a;zhuan[0][1] = b;zhuan[0][2] = c;        zhuan[0][3] = d;zhuan[0][4] = e;zhuan[0][5] = f;        zhuan[0][6] = g;zhuan[0][7] = h;zhuan[0][8] = i;        for(int j = 1;j <=8 ;j++)            for(int i = 0;i < 9 - j;i++)                zhuan[j][i] = zhuan[j - 1][i] + zhuan[j - 1][i + 1];        for(int i = 8;i >= 0;i--)        {            for(int j = 0;j < 9 - i;j++)            {                if(j == 0) printf("%d",zhuan[i][j]);                else printf(" %d",zhuan[i][j]);            }            printf("\n");        }    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.