HDU 5538 House Building(模拟——思维)

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5538

Problem Description

Have you ever played the video game Minecraft? This game has been one of the world‘s most popular game in recent years. The world of Minecraft is made up of lots of 1×1×1 blocks in a 3D map. Blocks are the basic units of structure in Minecraft, there are 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 game.


Figure 1: A typical world in Minecraft.

Nyanko-san is one of the diehard fans of the game, what he loves most is to build monumental houses in the world of the game. 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 a n×m 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 is a important element to decorate his house. Now Nyanko-san gives you his blueprint of house and asking for your help. Your job is quite easy, collecting a sufficient number of the glass unit for building his house. But first, you have to calculate how many units of glass should be collected.

There are n rows and m columns on the ground, an intersection of a row and a column is a 1×1 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 array ci,j(1≤i≤n,1≤j≤m). Which ci,j indicates the height of his house on the square of i-th row and j-th column. The number of glass unit that you need to collect is equal to the surface area of Nyanko-san‘s house(exclude the face adjacent to the ground).

Input

The first line contains an integer T indicating the total number of test cases.
First line of each test case is a line with two integers n,m.
The n lines that follow describe the array of Nyanko-san‘s blueprint, the i-th of these lines has m integers ci,1,ci,2,...,ci,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 line.

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

20Figure 2: A top view and side view image for sample test case 1.

Source

2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)

题意描述:

输入矩阵的大小及矩阵,计算该3维立体结构的表面积(底面积除外)

解题思路:

模拟处理,细心即可。

AC代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 int map[60][60];
 4 int main()
 5 {
 6     int T,i,j,k,sum,n,m,tx,ty;
 7     int next[4][2]={0,1,1,0,0,-1,-1,0};
 8     scanf("%d",&T);
 9     while(T--)
10     {
11         scanf("%d%d",&n,&m);
12         memset(map,0,sizeof(map));
13         for(i=1;i<=n;i++)
14             for(j=1;j<=m;j++)
15                 scanf("%d",&map[i][j]);
16         sum=0;
17         for(i=1;i<=n;i++)
18         {
19             for(j=1;j<=m;j++)
20             {
21                 if(map[i][j])
22                 {
23                     sum++;
24                     for(k=0;k<=3;k++)
25                     {
26                         tx=i+next[k][0];
27                         ty=j+next[k][1];
28                         if(map[i][j] > map[tx][ty])
29                         sum += (map[i][j] - map[tx][ty]);
30                     }
31                 }
32             }
33         }
34         printf("%d\n",sum);
35     }
36     return 0;
37 }
时间: 2024-12-25 11:22:42

HDU 5538 House Building(模拟——思维)的相关文章

hdu 5538 House Building(长春现场赛——水题)

题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538 House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 621    Accepted Submission(s): 398 Problem Description Have you ever played the vid

2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building

House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 145    Accepted Submission(s): 123 Problem Description Have you ever played the video game Minecraft? This game has been one of t

HDU 5538 House Building 瞎搞

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 Description Have you ever played the video game Minecraft? This game has been one of

hdu 5538 House Building 【矩阵表面积】

House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1808    Accepted Submission(s): 1138 Problem Description Have you ever played the video game Minecraft? This game has been one of

hdu 1175 连连看(模拟循环队列)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18149    Accepted Submission(s): 4741 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通过一条线连起来(这条

HDU 4608 I-number--简单模拟

I-number Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The I-number of x is defined to be an integer y, which satisfied the the conditions below: 1.  y>x; 2.  the sum of each digit of y(under base 10) is the multiple of 10; 3.  among all

hdu 4831 Scenic Popularity(模拟)

题目链接:hdu 4831 Scenic Popularity 题目大意:略. 解题思路:对于休闲区g[i][0]和g[i][1]记录的是最近的两个景点的id(只有一个最近的话g[i][1]为0),对于景点来说,g[i][0]为-1(表示该id对应的是景点),g[i][1]为该景点的热度值.主要就是模拟,注意一些细节就可以了. #include <cstdio> #include <cstring> #include <cstdlib> #include <alg

HDU 6154 CaoHaha&#39;s staff 思维 找规律

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6154 题目描述: 围成一个面积不小于S的多边形, 最少需要多少根儿线段, 线段可以为单元格边或者对角线 解题思路: 最大的面积肯定是由根号2为边长的正方形围成了, 那么我们把所有正方形都遍历一遍, 找出S介于N, N+1的那个上界N+1设为max, 因为MAX所围成的多边形面积和MAX-1, MAX-2, MAX-3围成的多边形面积, 找出满足条件的最小的一个即可 代码: #include <io

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp