(简单递推)UVA-11040Add bricks in the wall

Add bricks in the wall
递推关系很容易得出,
主要注意的是图的存储以及访问。
将图中的金字塔形,转换成下三角形

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;

int ncase,map[15][15];
int main(){
    cin>>ncase;
    while (ncase--)
    {
        for(int i=1;i<=5;i++)
        {
            for(int j=1;j<=i;j++)
            {
                scanf("%d",&map[2*i-1][2*j-1]);
            }
        }
        for(int i=1;i<=5;i++)
        {
            for(int j=1;j<=i;j++)
            {
                int c =map[2*i-1][2*j-1],a=map[2*i+1][2*j-1],b=map[2*i+1][2*j+1];
                int x = (c-a-b)/2;
                map[2*i+1][2*j]=x;
                map[2*i][2*j-1]=a+x;
                map[2*i][2*j]=b+x;
            }
        }
        for(int i=1;i<=9;i++)
        {
            for(int j=1;j<=i-1;j++)
                printf("%d ",map[i][j]);
            printf("%d\n",map[i][i]);
        }
    }
    return 0;
}
发布了67 篇原创文章 · 获赞 0 · 访问量 1496

猜你喜欢

转载自blog.csdn.net/qq_44846324/article/details/104594162