HDU 5538 House Building

Source: Internet
Author: User

House Building

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


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 of1x1x1 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 integerTindicating 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 31 0 03 1 21 1 03 31 0 10 0 01 0 1

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

SOURCE2015ACM/ICPC Asia Changchun Station-Replay (thanks to northeast Normal University)

Recommendhujie | We have carefully selected several similar problems for you:5877 5876 5875 5874 5873 The problem is to find the surface area, and then the bottom side, don't judge it.
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin), #define FOUT freopen ("Output.txt", "w", stdout); #define INF 0x3f3f 3f3f#define infll 0x3f3f3f3f3f3f3f#define Lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef Long Long LL typedef pair<int,int> PII;CONST int MAXN = + 5;int mp[maxn][maxn];int t;int N, m;int cnt;int to[4][2] = {1, 0,-    1, 0, 0,-1, 0, 1};void llss (int x, int y) {if (mp[x][y] = = 0) return;        for (int i = 0; i < 4; i++) {int xx = x + to[i][0];        int yy = y + to[i][1];        if (Mp[xx][yy] >= mp[x][y]) {cnt-= mp[x][y];        } if (Mp[xx][yy] < Mp[x][y] && mp[xx][yy]! = 0) {cnt-= mp[xx][yy];    }}}int Main () {//fin scanf ("%d", &t); While(t--)        {memset (MP, 0, sizeof (MP));        scanf ("%d%d", &n, &m);        CNT = 0;        int num = 0;                for (int i = 1; I <= n; i++) {for (int j = 1; j <= M; j + +) {scanf ("%d", &mp[i][j]);                CNT + = Mp[i][j];            if (mp[i][j]! = 0) num++;        }} CNT *= 6;        cout << cnt << Endl;                for (int i = 1; I <= n; i++) {for (int j = 1; j <= M; j + +) {LLSS (i, j);                if (Mp[i][j] >= 2) {cnt-= (Mp[i][j]-1) * 2;            }//cout << cnt << Endl;        }} cnt-= num;    printf ("%d\n", CNT); } return 0;}

  

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.