[Hdu5538] [5acm/ICPC Changchun station in Asia] House Building Question & code

Source: Internet
Author: User

[Hdu5538] [5acm/ICPC Changchun station in Asia] House Building Question & code

Question:
In the top view of the building block chart, input data indicates that (I, j) is placed with a building block with the height of h [I] [j, calculate the surface area (not the lower surface !!!).
Question:
A question, such as me, can quickly think of a question... See the code implementation for details.
Code:

#include
  
   #include#include
   
    #include
    
     using namespace std;int T,n,m,h[55][55];int main(){    scanf("%d",&T);    while(T--)    {        scanf("%d%d",&n,&m);        memset(h,0,sizeof(h));        for (int i=1;i<=n;i++)        for (int j=1;j<=m;j++)        scanf("%d",&h[i][j]);        int ans=0;        for (int i=1;i<=n;i++)        for (int j=1;j<=m;j++)        {            if (h[i][j]!=0) ans++;            if (h[i][j]>h[i-1][j]) ans+=h[i][j]-h[i-1][j];            if (h[i][j]>h[i+1][j]) ans+=h[i][j]-h[i+1][j];            if (h[i][j]>h[i][j-1]) ans+=h[i][j]-h[i][j-1];            if (h[i][j]>h[i][j+1]) ans+=h[i][j]-h[i][j+1];            //cout<
     
    
   
  

Related Article

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.