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",现 ...
随机推荐
- ES6 let和const命令(2)
为什么要使用块级作用域 在ES5中只有全局作用域和函数作用域,没有块级作用域,因此带来了这些麻烦 内层变量可能会覆盖外层变量 var tmp = new Date(); console.log(tmp ...
- python+selenium自动化测试_1
前言 回顾一下python+selenium基础,并整理相关知识点,分享给有需要,在前进道路上的朋友. print打印 #打印Hello World print("Hello World&q ...
- 记录python学习过程中的一些小心得
1.python中一切皆对象,内置数据结构也是对象.处理一个对象就是利用它带有的方法和属性,对该对象进行处理,一步步达到我们想要的结果. 2.编程时,先构思好我们处理的对象是什么,具有哪些属性和方法, ...
- angularjs 怎么获取鼠标焦点 鼠标移入显示浮动的div提示框
首先,我们要清楚几个基础的知识,angular的两个鼠标移入移出的指令------ng-mouseover(鼠标移入)ng-mouseleave(鼠标移出)--------还有就是window.eve ...
- java inputstream to string stack overflow
https://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string 过千赞的答案
- 构建布局良好的Windows程序
工具箱→菜单和工具栏菜单栏MenuStrip的类型MenuItem:菜单项TextBox:文本框ComboBoX:组合框Separato:分割线前面都有ToolStrip做前缀 Applaction. ...
- JavaScript 浏览器类型及版本号
项目中偶尔用到判断浏览器类型及相关版本问题,现记录相关代码: function getBrowserVertion(userAgent) { var browserName, browserVersi ...
- angular4.0配置本机IP访问项目
一.查看本机IP 命令行输入 ipconfig,在面板中选择IPv4地址 二.在项目中配置IP 打开package.json文件,修改如下 三.命令行运行 npm start 四.在手机上访问 192 ...
- 第一章:Python基础の快速认识基本语法
本課主題 第一个 Hello World 程序实战 用户输入实战 模块介紹 变量介绍 格式化介紹 条件判断介紹和操作实战 for 循环介紹和操作实战 作业需求 Python 第一个 Hello Wor ...
- ORM框架 EF - code first 的封装 优化一
上一节我们讲到对EF(EntityFramework)的初步封装,任何事情都不可能一蹴而就,通过大量的实际项目的实战,也发现了其中的各种问题.在这一章中,我们对上一章的EF_Helper_DG进行优化 ...