HDU 5538 House Building (Changchun Live race)

Source: Internet
Author: User

Topic Links:

HDU 5538 House Building House Building

Title: Given a top view of a building block, and the height of each coordinate block, calculate the surface area of the entire stereoscopic map (excluding the bottom surface area).
Problem-Solving ideas: Add a frame to a given top view, and compare each point of the top view with the top and bottom of each point to calculate the increment (height difference).
Input
The first line contains a integer T indicating the total number of test cases.
First line of all test case was a line with the integers n,m.
The n lines that follow describe the array of Nyanko-san ' s blueprint, the i-th of these lines have m integers ci,1,ci,2,..., c I,m, separated by a single space.

1≤t≤50
1≤n,m≤50
0≤ci,j≤1000

Output
For each test case, please output the number of glass units you need to collect to meet Nyanko-san ' s requirement in one Li Ne.

Sample Input
2
3 3
1 0 0
3 1 2
1 1 0
3 3
1 0 1
0 0 0
1 0 1

Sample Output
30
20

#include <iostream> #include <cstdio> #include <cstring> using namespace std;
    int main () {int k,n,m,i,j,area[4],sum,ans;
    int a[101][101];
    scanf ("%d", &k);
    while (k--) {ans=0;
    scanf ("%d%d", &n,&m);
         for (i=0;i<=n+1;i++) for (j=0;j<=m+1;j++) a[i][j]=0;//increase the border, put each clears 0 for (i=1;i<=n;i++)

     for (j=1;j<=m;j++) scanf ("%d", &a[i][j]);
             for (i=1;i<=n;i++) {for (j=1;j<=m;j++) {sum=0;
                 if (a[i][j]!=0) {if (a[i][j]>a[i][j-1]) area[0]=a[i][j]-a[i][j-1];
                 else area[0]=0;
                 if (a[i][j]>a[i][j+1]) area[1]=a[i][j]-a[i][j+1];
                 else area[1]=0;
                 if (A[i][j]>a[i-1][j]) area[2]=a[i][j]-a[i-1][j];
                 else area[2]=0; if (a[i][J]&GT;A[I+1][J]) area[3]=a[i][j]-a[i+1][j];
                 else area[3]=0;
                sum=area[0]+area[1]+area[2]+area[3]+1;//Calculate the height difference ans=ans+sum;
    }}} printf ("%d\n", ans);
} 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.