博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF:3D City Model(小思维)
阅读量:6085 次
发布时间:2019-06-20

本文共 3183 字,大约阅读时间需要 10 分钟。

链接:http://codeforces.com/gym/101246/problem/B

B. 3D City Model
time limit per test
1 second
memory limit per test
256 megabytes
input
input.txt
output
output.txt

A city is built on the top of a rectangular n × m grid where all the grid cells are equal squares. Each of the n·m grid cells can serve as a foundation of a single building in the city. A building is represented as a number of 1 × 1 × 1 cubes stacked on the top of each other. The cube that lays in the foundation of a building entirely occupies a single cell on the grid. It is clear that adjacent buildings can share a wall or a part of it. Typical cities can be seen on the image below.

The King of Berland has a 3D model of the capital city in his office. This model was made on a special 3D-printer out of plastic. It represents a layout of the capital city, but the scale is smaller, so it's very convenient for the King to examine the model without having to visit the city itself. The King is bored though because the model is colorless, so he wants to paint the model. To calculate the exact amount of required paint he should know the total area of the model's surface.

You have to help the King and write a program that will calculate the required surface area of the given model. While calculating the surface area you should count not only the side surfaces, but also the areas of the top and bottom facets.

The model is given to you as n × m matrix of digits. A digit in the j-th position of the i-th row stands for the height of the building with its foundation in cell (i, j) of the model. If the corresponding digit is equal to "0", it means there is no building built on the top of this cell.

Input

The first line of input contains a pair of integers n, m (1 ≤ n, m ≤ 100), where n — amount of rows in the given grid, m — amount of columns. The following n lines contain the description of the model. These n lines contain m digits each representing heights of the buildings. It's guaranteed that the given matrix contains at least one non-zero digit.

Output

Output the only positive integer — surface area of the model.

Examples
input
3 3111212111
output
38
input
3 4100000100000
output
12
Note

The first sample test corresponds to the leftmost picture from the problem statement.

题意:一座n*m的城市,给出俯视图各个点的楼层数,求出整体的表面积。

思路:每一个点,通过它前后左右与他本身的高度差计算即可。

# include 
# include
# include
# include
using namespace std;char a[105][105];int main(){ int n, m; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d%d",&n,&m); int ans = 0, cnt = 0; memset(a, 0, sizeof(a)); for(int i=1; i<=n; ++i) { scanf("%s",a[i]+1); for(int j=1; j<=m; ++j) a[i][j] -= '0'; } for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) { if(a[i][j]) ++cnt; ans += max(a[i][j]-a[i][j+1], 0); ans += max(a[i][j]-a[i+1][j], 0); ans += max(a[i][j]-a[i][j-1], 0); ans += max(a[i][j]-a[i-1][j], 0); } ans += (cnt<<1); printf("%d\n", ans); return 0;}

转载于:https://www.cnblogs.com/junior19/p/6729954.html

你可能感兴趣的文章
全局探色器
查看>>
Hive Export和Import介绍及操作示例
查看>>
http://mongoexplorer.com/ 一个不错的 mongodb 客户端工具。。。
查看>>
Xcode 4.3 使用xcodebuild命令编译项目环境设置
查看>>
上传jar包到nexus私服
查看>>
Why Namespace? - 每天5分钟玩转 OpenStack(102)
查看>>
Project:如何分析项目中的资源分配情况
查看>>
HDU 4803 Poor Warehouse Keeper (贪心+避开精度)
查看>>
小错误汇总
查看>>
AVX2整数向量运算
查看>>
POJ2559 HDU1506 ZOJ1985 Largest Rectangle in a Histogram【堆栈】
查看>>
POJ NOI0105-41 数字统计
查看>>
各类电压标准
查看>>
Yii2 提供可以用属性的方式去获取类的一个方法
查看>>
安装Jenkins(基于Ubuntu Desktop 12.04 LTS)
查看>>
c++复习总结
查看>>
Cow Uncle 学习了叉积的一点运用,叉积真的不错
查看>>
caffe源码 池化层 反向传播
查看>>
scikit-learn包的学习资料
查看>>
安卓开发学习笔记—————《第一行代码》第四章 探究碎片 (Fragment和RecyclerView实践)...
查看>>