SGU - 519 - 3D City Model (模拟)
2015-03-18 22:43
274 查看
519. 3D City Model
Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes
input: standard
output: standard
A city is built on the top of a rectangular n x 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 x 1 x 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.
![](http://acm.sgu.ru/problems/0/p519_01.png)
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 x 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 nlines
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.
Example(s)
sample input | sample output |
3 3 111 212 111 | 38 |
sample input | sample output |
3 4 1000 0010 0000 | 12 |
The first sample test corresponds to the leftmost picture from the problem statement.
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n, m; int map[105][105]; int xx[4] = {-1, 0, 1, 0}, yy[4] = {0, 1, 0, -1}; int fun(int x, int y) { int ret = 0; if(map[x][y] == 0) return 0; if(map[x][y] > 0) ret += 2; for(int i = 0; i < 4; i++) { if(map[x][y] > map[x + xx[i]][y + yy[i]]) ret += (map[x][y] - map[x+xx[i]][y+yy[i]]); } return ret; } int main() { while(scanf("%d %d", &n, &m) != EOF) { memset(map, 0, sizeof(map)); for(int i = 1; i <= n; i++) { char tmp[105]; scanf("%s", tmp); int len = strlen(tmp); for(int j = 0; j < len; j++) map[i][j+1] = tmp[j] - '0'; } int ans = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j<= m; j++) { ans += fun(i, j); } } printf("%d\n", ans); } return 0; }
相关文章推荐
- sgu - 519 - 3D City Model
- SGU 271 双端队列 和 栈 模拟
- 使用GDI+模拟directx 3D渲染中的坐标变换
- 【SGU】271. Book Pile(双端队列模拟)
- iOS 模拟轮胎滚动3D动画效果
- 非3D Touch的设备上模拟Peek Preview效果
- jQuery 模拟 ubuntu 3D desktop 的 Dodge Effect 效果
- SGU - 316 - Code Tanks (简单模拟)
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest B. 3D City Model(数论)
- Sarov zones(SGU171,排序+模拟,)
- sgu 102模拟欧拉函数
- sal3d WIBU加密狗破解复制模拟 写狗工具
- 3D打印太空应用升级:可在AMADEE-18火星模拟任务中制作备件
- sgu - 274 - Spam-filter(模拟)
- 基于3D路口安全系数的导航决策系统--三维行车模拟版块实现
- 基于GPU的3D流体模拟
- SGU 126. Boxes --- 模拟
- sgu 102模拟欧拉函数
- 基于GPU的3D流体模拟
- SGU 127. Telephone directory --- 模拟