HDU-5538 House Building

Source: Internet
Author: User

Time limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 1100 Accepted Submission (s): 674

Problem Descriptionhave You ever played the video game Minecraft? This game had been one of the world's most popular game in recent years. The world of Minecraft are made up of lots of 1x1x1 blocks in a 3D map. Blocks is the basic units of structure in Minecraft, there is many types of Blocks. A block can either be a clay, dirt, water, wood, air, ... or even a building material such as brick or concrete in this GA Me.


Figure 1: A typical world in Minecraft.

Nyanko-san is one of the diehard fans of the game, what he loves most are to build monumental houses in the world of the GA Me. One day, he found a flat ground in some place. Yes, a super flat ground without any roughness, it's really a lovely place-to-build houses on it. Nyanko-san decided to build on anxm Big flat ground, so he drew a blueprint of his house, and found some building materials to build.

While everything seems goes smoothly, something wrong happened. Nyanko-san found out he had forgotten to prepare glass elements, which was a important element to decorate his house. Now Nyanko-san gives-blueprint of house and asking for your help. Your job is quite easy, collecting a sufficient number of the glass unit for building he house. But first, you had to calculate how many units of the glass should be collected.

There isNRows andmColumns on the ground, an intersection of a row and a column is a1x1 Square,and a square is a valid place for players to put blocks on. And to simplify this problem, Nynako-san's blueprint can be represented as an integer arrayc i ,j (1≤ i≤ n, 1≤j ≤m ) /span> . whichcI,J Indicates the height of his house on the square of i-th row and J-th column. The number of glass unit so need to collect are equal to the surface area of Nyanko-san ' s house (exclude the face Adja cent to the ground).

Inputthe first line contains an integer Tindicating the total number of test cases.
First line of all test case was a line with the integersn,m .
TheNLines that follow describe the array of Nyanko-san ' s blueprint, theI-th of these lines hasmIntegersCI,1, ci,2,.< Span id= "mathjax-span-97" class= "Mo". ,ci,m , separated by a single space.

1≤T≤
1≤n,m≤
0≤ci,j≤

Outputfor Each test case, please output the number of glass units your need to collect to meet Nyanko-san ' s requirement in One line.

Sample Input23 0 1 of 1 0 0 to 0 1 Sample Output3020 Figure 2: A top view and side view, image for sample, test Case 1.

Test instructions

The surface area of the given body is obtained.

As long as h[i][j] is not empty then +1, each i,j is divided into four sides, each side plus i,j higher than the number of adjacent polygons.

The AC code is attached:

1#include <bits/stdc++.h>2 using namespacestd;3 4 inth[ -][ -];5 6 intMain () {7     intT;8Cin>>T;9      while(t--){Ten         intn,m; OneCin>>n>>m; A         intans=0; -memset (H,0,sizeof(h)); -          for(intI=1; i<=n;i++){ the              for(intj=1; j<=m;j++){ -Cin>>H[i][j]; -                 if(h[i][j]>0) -ans++; +             } -         } +         intsum=0; A          for(intI=1; i<=n;i++){ at              for(intj=1; j<=m;j++){ -                 if(h[i][j]>h[i-1][j]) -sum+=h[i][j]-h[i-1][j]; -                 if(h[i][j]>h[i+1][j]) -sum+=h[i][j]-h[i+1][j]; -                 if(h[i][j]>h[i][j-1]) insum+=h[i][j]-h[i][j-1]; -                 if(h[i][j]>h[i][j+1]) tosum+=h[i][j]-h[i][j+1]; +             } -         } thecout<<sum+ans<<Endl; *     } $     return 0;Panax Notoginseng}

HDU-5538 House Building

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.