题目链接: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. php通过$_SERVER['HTTP_USER_AGENT']获取浏览器相关参数

    最近不忙,同事在忙一个app项目.当听到领导安排让他做一个判断苹果还是安卓手机,如果是安卓手机下载安卓app.如果是苹果手机下载苹果app;然后我就上网搜了一下学习学习: php通过$_SERVER[ ...

  2. 一、Ubuntu 简介

    Ubuntu 是一个Linux 系统 Apt-Get apt-get 命令是一个强大的命令行工具,用于同 Ubuntu 的 Advanced Packaging Tool (APT) 一起执行诸如安装 ...

  3. 10.1综合强化刷题 Day3

    括号序列(bracket) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一个括号序列,但这个序列不一定合法. 一个合法的括号序列如下: ()是合法的 ...

  4. luogu P2043 质因子分解

    题目描述 对N!进行质因子分解. 输入输出格式 输入格式: 输入数据仅有一行包含一个正整数N,N<=10000. 输出格式: 输出数据包含若干行,每行两个正整数p,a,中间用一个空格隔开.表示N ...

  5. 2016北京集训测试赛(七)Problem A: 自动机

    Solution 注意到这一题并不要求字符串最短或者是字典序最小, 因此直接构造就可以了. 我们对于每个点\(u \ne 0\)找到一个串\(S\), 使得\(T(u, S) = T(0, S)\), ...

  6. BZOJ 3029 守卫者的挑战

    题面 Description 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜寻着关押applepi的监狱的所在地.突然,眼前一道亮光闪过."我,Nizem,是黑魔法圣殿的守卫 ...

  7. 在Android中实现阴影效果

    在Android L推出后,Google提出了全新的设计语言:材质设计.其中很重要的一点就是阴影效果的使用,你可以为每一个View设置一个elevation值,相当于除了x.y之外的z值,z值决定了阴 ...

  8. php 列出当前目录

    $path="."; //初使化用户所操作目录 $prevpath=dirname($path); //初使化当前脚本所在目录 $dir_handle=opendir($path) ...

  9. css样式大全(整理版)

    字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...

  10. Linux USB驱动数据结构

    struct usb_ctrlrequest {    __u8 bRequestType;    __u8 bRequest;    __le16 wValue;    __le16 wIndex; ...