House Building

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1958    Accepted Submission(s): 1223

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
 
  • 计算立方体表面积
  • 对于给出的每个高度,先算排除底面的表面积,然后减去旁边四面高度的min就是当前立方体表面积
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cmath>
  8. #include <vector>
  9. #include <queue>
  10. #include <stack>
  11. #include <set>
  12. #include <map>
  13. using namespace std;
  14. typedef long long LL ;
  15. typedef unsigned long long ULL ;
  16. const int maxn = 1e3 + ;
  17. const int inf = 0x3f3f3f3f ;
  18. const int npos = - ;
  19. const int mod = 1e9 + ;
  20. const int mxx = + ;
  21. const double eps = 1e- ;
  22. const double PI = acos(-1.0) ;
  23.  
  24. int T, n, m, a[maxn][maxn];
  25. LL ans;
  26. int main(){
  27. // freopen("in.txt","r",stdin);
  28. // freopen("out.txt","w",stdout);
  29. while(~scanf("%d",&T)){
  30. while(T--){
  31. ans=;
  32. memset(a,,sizeof(a));
  33. scanf("%d %d",&n,&m);
  34. for(int i=;i<=n;i++)
  35. for(int j=;j<=m;j++)
  36. scanf("%d",&a[i][j]);
  37. for(int i=;i<=n;i++)
  38. for(int j=;j<=m;j++)
  39. if(a[i][j])
  40. ans+=(*a[i][j]+)
  41. -min(a[i][j],a[i-][j])-min(a[i][j],a[i+][j])
  42. -min(a[i][j],a[i][j-])-min(a[i][j],a[i][j+]);
  43. printf("%lld\n",ans);
  44. }
  45. }
  46. return ;
  47. }

HDU_5538_House Building的更多相关文章

  1. Building the Testing Pipeline

    This essay is a part of my knowledge sharing session slides which are shared for development and qua ...

  2. BZOJ 4742: [Usaco2016 Dec]Team Building

    4742: [Usaco2016 Dec]Team Building Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 16[Su ...

  3. Building OpenCASCADE on Debian

    Building OpenCASCADE on Debian eryar@163.com Abstract. When you are familiar with OpenCASCADE on Win ...

  4. Building third-party products of OpenCascade

    Building third-party products of OpenCascade eryar@163.com Available distributives of third-party pr ...

  5. Building OpenCascade on Windows with Visual Studio

    Building OpenCascade on Windows with Visual Studio eryar@163.com 摘要Abstract:详细说明OpenCascade的编译配置过程,希 ...

  6. CentOS 6.3 中安装VirtualBOX增强工具失败:Building the main Guest Additions module[FAILED]

    在VirtualBox里安装CentOS系统,会遇到“增强工具”无法正常安装,主要的原因是出在Kernel 库找不到. 错误提示如下:  通过查看日志文件: cat /var/log/vboxadd- ...

  7. Android Studio在创建/导入项目的时候,一直处于building “XXX”gradle project info的解决办法

    Android Studio在新建项目或者导入项目的时候,可能会一直处于building “XXX”gradle project info的状态,而且还取消不了,无奈之下只能干掉进程... 还有一种情 ...

  8. Download Free Oracle Reports Building Guide eBook

    A very nice ebook on building reports in Oracle fusion middleware 11g. This manual is intended for a ...

  9. 【问题】AndroidStudio导入项目一直卡在Building gradle project infod的最快速解决方案

    原因 AndroidStudio导入项目一直卡在Building gradle project info的原因, 是因为导入的这个项目使用的gradle版本与本地已经拥有的gradle版本不一致,导致 ...

随机推荐

  1. 【Android】12.6 利用Intent实现记事本功能(NotePad)

    分类:C#.Android.VS2015: 创建日期:2016-02-23 一.简介 这个例子演示如何实现一个简单的记事本功能. 该例子提前使用了后面章节将要介绍的SQLLite数据库. 二.示例-c ...

  2. iptables安装失败后-------------firewalld回归

    yum install firewalld systemctl stop iptables; systemctl mask iptables; systemctl unmask firewalld s ...

  3. win32之全屏窗口

    游戏开发中经常使用会让游戏以全屏窗口的状态运行,下面一个例子就是来实现这个效果的. #include <windows.h> void RegisterMyClass(); LRESULT ...

  4. FreeRTOS 调度锁,任务锁和中断锁

    以下转载自安富莱电子: http://forum.armfly.com/forum.php 调度锁调度锁就是 RTOS 提供的调度器开关函数,如果某个任务调用了调度锁开关函数,处于调度锁开和调度锁关之 ...

  5. 【基础练习】【区间DP】codevs2102 石子归并2(环形)题解

    题目描写叙述 Description 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次仅仅能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个 ...

  6. Android开发之Fragment传递參数的几种方法

    Fragment在Android3.0開始提供,而且在兼容包中也提供了Fragment特性的支持. Fragment的推出让我们编写和管理用户界面更快捷更方便了. 但当我们实例化自己定义Fragmen ...

  7. Unix系统编程()进程内存布局

    每个进程所分配的内存由很多部分组成,通常称之为"段(segment)". 文本段包含了进程运行的程序机器语言指令.文本段具有只读属性,以防止进程通过错误指针意外修改自身指令. 因为 ...

  8. springboot集成模板引擎freemarker和thymeleaf

    freemarkder和thymeleaf都是java的模板引擎,这里只介绍这两种模板引擎如何在sprongboot中配置: 1. freemarkder 1.1 在pom.xml中添加依赖包 < ...

  9. VB.NET &amp; 策略模式(下机用户类型选择)

    上篇文章讲述了对于下机操作和基本数据设定的时间联系,今天主要就是应用"策略模式"来了解了解对于固定用户,以及暂时用户之间的选择,看学习设计模式的时候自己对于策略模式的理解,我们能够 ...

  10. java的开发主要以http为基础

    java的开发主要以http为基础. 反射:主要用于工具和框架的开发. 反射是对于类的再抽象:通过字符串来抽象类. JAVA类的运行:classLoader:加载到虚拟机(vm) Vm中只能存储对象( ...