题目链接: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 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
20
Figure 2: A top view and side view image for sample test case 1.
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5664 5663 5662 5661 5660 
 

题目大意:

题目大意:给你积木图的鸟瞰图。(i,j)位置放了一个高度为a[i][j]的积木,求表面积(不算下表面)。

解题思路:签到题吧,从上下左右四个方向扫一下相邻两个积木的高度差就能够了。
详见代码。

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int t,n,m,k,ans;
int a[110][110];
scanf("%d",&t);
while (t--)
{
memset(a,0,sizeof(a));
scanf("%d%d",&n,&m);
k=0;
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
scanf("%d",&a[i][j]);
if (a[i][j]>0)
k++;
}
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
ans=a[i][j]-a[i][j+1];
if (ans>0)
k+=ans;
}
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
ans=a[i][j]-a[i][j-1];
if (ans>0)
k+=ans;
}
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
ans=a[i][j]-a[i-1][j];
if (ans>0)
k+=ans;
}
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
ans=a[i][j]-a[i+1][j];
if (ans>0)
k+=ans;
}
}
printf ("%d\n",k);
}
return 0;
}


hdu 5538 House Building(长春现场赛——水题)的更多相关文章

  1. hdu 4813(2013长春现场赛A题)

    把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...

  2. HDU 4813 Hard Code(水题,2013年长春现场赛A题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4813 签到题. 把一个字符串按照格式输出就可以了,很水 #include <stdio.h> ...

  3. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  4. hdu 5078 2014鞍山现场赛 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...

  5. HDU 4821 String(2013长春现场赛I题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821 字符串题. 现场使用字符串HASH乱搞的. 枚举开头! #include <stdio.h ...

  6. HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  7. HDU 4818 Golden Radio Base (2013长春现场赛B题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 进制转换. 现场根据题目给的两个公式,不断更新!!! 胡搞就可以了. 现场3A,我艹,一次循环开 ...

  8. HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...

  9. HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...

随机推荐

  1. 八、 Java程序初始化的顺序(一)

    今天在写构造器方法的时候,遇到了一个小问题,由这个问题引发了一连串的思考,在一个Java类中变量与类的初始化执行顺序是什么样的呢?## 发现问题 class Student{ private Stri ...

  2. JdbcTemplate模板使用

    1.添加模板的配置文件 在spring的配置文件中加入如下代码 <bean class="org.springframework.jdbc.core.JdbcTemplate" ...

  3. ConstraintLayout 约束布局

    约束布局ConstraintLayout 这种布局方式出现已经有一段时间了,刚出现的时候一直以为这种布局只是针对拖拽使用的布局,最近在新项目里看到了这种布局,又重新学习了这种布局,才发现以前真的是图样 ...

  4. Pacman常用命令

    Pacman是Arch Linux 的包管理器.它将一个简单的二进制包格式和易用的构建系统结合了起来.不管软件包是来自官方的 Arch 库还是用户自己创建,Pacman 都能方便得管理. 更新系统 在 ...

  5. POJ1655 Balancing Act(树的重心)

    题目链接 Balancing Act 就是求一棵树的重心,然后统计答案. #include <bits/stdc++.h> using namespace std; #define REP ...

  6. addEventListener与attachEvent

    一.attachEvent和addEventListener (一)addEventListener addEventListener() 方法用于向指定元素添加事件句柄.使用 removeEvent ...

  7. 10.1综合强化刷题 Day3 afternoon

    竞赛时间:????年??月??日??:??-??:?? 题目名称 a b c 名称 a b c 输入 a.in b.in c.in 输出 a.out b.out c.out 每个测试点时限 1s 1s ...

  8. golang:mgo剖析之Session

    golang操作mongo使用的包是"gopkg.in/mgo.v2",coding过程中需要并发读写mongo数据库,简单观摩了下源码,记录下自己的一些理解,如有错误,敬请斧正. ...

  9. EasyMvc入门教程-基本控件说明(11)菜单导航

    基本上,是个网站就会有菜单导航,目前流行的菜单是不是这样样子的? 似乎是bootstrap引领的风格,我们就用EasyMvc实现吧,上代码: @{ var data = new List<Men ...

  10. 【重点突破】——Canvas技术绘制音乐播放器界面

    一.引言 在用Canvas练习制作了验证码之后,还有一个用Canvas技术很综合的练习——制作音乐播放器.在做这个练习的过程中,还有一个重要的观察点,那就是理解Canvas的一大问题. 二.要求  点 ...