hdu 5538 House Building(长春现场赛——水题)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538
House Building
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).
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
2
3 3
1 0 0
3 1 2
1 1 0
3 3
1 0 1
0 0 0
1 0 1
30
20
Figure 2: A top view and side view image for sample test case 1.
题目大意:
#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(长春现场赛——水题)的更多相关文章
- hdu 4813(2013长春现场赛A题)
把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...
- HDU 4813 Hard Code(水题,2013年长春现场赛A题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4813 签到题. 把一个字符串按照格式输出就可以了,很水 #include <stdio.h> ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
- hdu 5078 2014鞍山现场赛 水题
http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...
- HDU 4821 String(2013长春现场赛I题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821 字符串题. 现场使用字符串HASH乱搞的. 枚举开头! #include <stdio.h ...
- HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 4818 Golden Radio Base (2013长春现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 进制转换. 现场根据题目给的两个公式,不断更新!!! 胡搞就可以了. 现场3A,我艹,一次循环开 ...
- HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...
- HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...
随机推荐
- android日期时间选择器
android原生的日期时间控件,因为是原生的总有其满足不了我们需求的时候,Android 手机版本那么多,用户弹出来的控件五花八门.因为项目需要,在网上找了一 些demo看了看,感觉有些写的很好,很 ...
- Unix进程和线程管理及其异同
Unix进程和线程管理及其异同 一,进程 1,什么是进程 在最初的单处理器系统中,系统中的多道程序按照一定规则切换而实现多任务处理,后来发现多个程序并发导致系统资源被共享,为了描述和管理程序对共享资源 ...
- COCI2017/2018 CONTEST #7
Prosjek 显然,越大的数应该越后参与平均数的计算,这样受较小数的影响就小一些 那我们就排个序,贪心的从最小的数开始往大的计算平均数即可 时间复杂度\(O(nlogn)\) Timovi 把分组分 ...
- (入门SpringBoot)SpringBoot结合拦截器(七)
SpringBoot拦截器: 拦截器还是照旧和springmvc一样: @Componentpublic class MyInterceptor implements HandlerIntercept ...
- OnTouchListener
1.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...
- Data structure basics - Java Implementation
Stack & Queue Implementations FixedCapacityQueue package cn.edu.tsinghua.stat.mid_term; import j ...
- 3D立体显示技术原理与游戏应用历程简介 【转】
本文来自 中关村ZOL 「3D 立体显示」可说是近来娱乐产业相当热门的话题,不但有好莱坞推出<阿凡达>等卖座 3D 立体电影,全球各大家电厂商也积极布局准备推出一系列支持 3D 立体显示的 ...
- TensorFlow笔记四:从生成和保存模型 -> 调用使用模型
TensorFlow常用的示例一般都是生成模型和测试模型写在一起,每次更换测试数据都要重新训练,过于麻烦, 以下采用先生成并保存本地模型,然后后续程序调用测试. 示例一:线性回归预测 make.py ...
- [javase学习笔记]-8.5 statickeyword的使用场景
这一节我们来看一下在我们开发的过程中,在什么时候我们要用到statickeyword进行静态修饰. 我们这里所说的静态.无非就是两种.一种是静态变量,一种是静态函数,我们分这两种情况进行说明stati ...
- django orm高级查询 F表达式和Q表达式以及分组annotate
1.关联关系映射及查询1.1django默认开启延迟加载所有多对1和1对1如果不使用select_related(),需要会延迟加载获取到相关对象,因为延迟可能会造成n+1次查询的问题,所以便有了se ...
