HDU 5538 House Building(模拟——思维)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5538
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).
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

题意描述:
输入矩阵的大小及矩阵,计算该3维立体结构的表面积(底面积除外)
解题思路:
模拟处理,细心即可。
AC代码:
#include<stdio.h>
#include<string.h>
int map[][];
int main()
{
int T,i,j,k,sum,n,m,tx,ty;
int next[][]={,,,,,-,-,};
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(map,,sizeof(map));
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&map[i][j]);
sum=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(map[i][j])
{
sum++;
for(k=;k<=;k++)
{
tx=i+next[k][];
ty=j+next[k][];
if(map[i][j] > map[tx][ty])
sum += (map[i][j] - map[tx][ty]);
}
}
}
}
printf("%d\n",sum);
}
return ;
}
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) ...
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 模拟+思维 HDOJ 5319 Painter
题目传送门 /* 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最 ...
- HDU 6187 Destroy Walls (思维,最大生成树)
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5122 K.Bro Sorting(模拟——思维题详解)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5122 Problem Description Matt's friend K.Bro is an A ...
- HDU 5538/ 2015长春区域 L.House Building 水题
题意:求给出图的表面积,不包括底面 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define ...
- HDU 5510---Bazinga(指针模拟)
题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...
- HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...
随机推荐
- Java 向下转型
1.Java 中父类直接向子类转型的不合法的,可以编译但运行时报错. Java中子类直接向父类转型 是合法的,但转型后,可以执行的方法仅限存在于父类中的,在执行时,先看子类的是否有定义,有就执行,没有 ...
- windows 下的python 安装pycrypto
一般在官方网站下载pycrypto: https://www.dlitz.net/software/pycrypto/ 然后使用命令就可以安装成功了: python setup.py build ...
- Nginx: http 跳转 https
参考:博文 参考:HTTP 状态码解读 Nginx - rewrite 方式 Nginx Server 配置 server { listen ; server_name www.test.com te ...
- Javascript中遍历数组方法的性能对比
Javascript中常见的遍历数组的方法 1.for循环 for(var i = 0; i < arr.length; i++) { // do something. } 2.for循环的改进 ...
- python3之迭代器&生成器
1.迭代器 迭代是Python最强大的功能之一,是访问集合元素的一种方式.. 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不 ...
- SAP的这三款CRM解决方案,您能区分清楚么
我的一位同事, John Burton, 在2017年12月底写过一篇博文:Explaining SAP's portfolio of "CRM Service" related ...
- 如何继承Date对象?由一道题彻底弄懂JS继承。
前言 见解有限,如有描述不当之处,请帮忙及时指出,如有错误,会及时修正. ----------长文+多图预警,需要花费一定时间---------- 故事是从一次实际需求中开始的... 某天,某人向我寻 ...
- linux下安装ffmpeg
1. 首先安装系统编译环境 yum install -y automake autoconf libtool gcc gcc-c++ #CentOS 2. 编译所需源码包 #yasm:汇编器,新版 ...
- python中的与 和 或
上周五写程序碰到需要处理多重判断的一个逻辑,一般正确的写法是: if a or b or (c and d) or e: pass 因为变量很长,看上去比较杂乱,自己灵机一动写成了如下的样子: if ...
- oracle查询16个小题
--1.查询出至少有一个雇员的所有部门 select Dept_id from emp group by Dept_id having count(*)>0; select dname from ...