Time Limit: 1 second

Memory Limit: 128 MB

【问题描述】

一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成。在每个网格上都可以有一个建筑,建筑由若干个1×1×1的立方体搭建而成(也就是所有建筑的底部都在同一平面上的)。几个典型的城市模型如下图所示:



现在给出每个网格上建筑的高度,即每个网格上建筑由多少个立方体搭建而成,要求这个建筑模型的表面积是多少。

【输入格式】

输入文件3d.in的第1行包含2个正整数n和m,为城市模型的长与宽。 接下来n行,每行m个数字字符,描述了网格每个格子高度(可见所有建筑高度都大等于0且小等于9)。

【输出格式】

输出文件3d.out包含一个非负整数,为城市模型的表面积。

【数据规模】

20%的数据满足:n, m≤10; 40%的数据满足:n, m≤100; 100%的数据满足:n, m≤1000。

Sample Input1

3 3

111

212

111

Sample Output1

38

Sample Input2

3 4

1000

0010

0000

Sample Output2

12

【题目链接】:http://noi.qz5z.com/viewtask.asp?id=u106

【题解】



看样例2可以知道,地面也算进去了;

所以遇到一个高度为0的格子,答案就递增2(上面和底面);

如果4个侧面有高于其他格子的部分,则也会露出来;递增相应答案就好;边界的侧面肯定会露出来;



【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second typedef pair<int,int> pii;
typedef pair<LL,LL> pll; void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} const int MAXN = 1e3+100;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); int n,m;
int a[MAXN][MAXN]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
memset(a,0,sizeof(a));
rei(n);rei(m);
rep1(i,1,n)
rep1(j,1,m)
{
char ch;
cin >> ch;
a[i][j] = ch-'0';
}
LL ans = 0;
rep1(i,1,n)
rep1(j,1,m)
if (a[i][j]>0)
{
ans+=2;
rep1(k,1,4)
{
int ti = i+dx[k],tj = j+dy[k];
if (a[i][j]>a[ti][tj])
ans+=(a[i][j]-a[ti][tj]);
}
}
cout << ans<<endl;
return 0;
}

最新文章

  1. Handler.sendMessage 与 Handler.obtainMessage.sendToTarget比较
  2. php进程占用大量cpu优化
  3. SeleniumIDE从0到1 (Selenium IDE 回放)
  4. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:
  5. wpf 将Style应用到 ListView 中的 ListViewItem 元素
  6. iOS快速单例宏
  7. android开发艺术探索
  8. 时序图 Sequence Diagram
  9. x264命令参数与代码中变量的对应关系
  10. cgo 随笔(golang)
  11. Ubuntu搭建Gitlab服务器
  12. 转 c#性能优化秘密
  13. 使用Redis中间件解决商品秒杀活动中出现的超卖问题(使用Java多线程模拟高并发环境)
  14. [luogu3377][左偏树(可并堆)]
  15. Nagios数据存储插件NDOUtils部署和测试
  16. .NET 同步与异步之锁(ReaderWriterLockSlim)(八)
  17. Git 重命名操作
  18. The NMEA 0183 Protocol
  19. 设计模式 笔记 工厂方法 Factory Methon
  20. (最小生成树)Agri-Net -- POJ -- 1258

热门文章

  1. POJ——T 3250 Bad Hair Day
  2. HTTP (httpwebrequest)
  3. HDU 2563 统计问题 (递推)
  4. DIV+CSS两种盒子模型(W3C盒子与IE盒子)
  5. jmeter响应数据中文乱码问题
  6. Codeforces Round #194 (Div. 2) 部分题解
  7. CSS min-height不能解决垂直外边距合并问题
  8. Docker 内程序时间设置,很重要
  9. 洛谷——U10783 名字被和谐了
  10. 有关 Lambda &amp;&amp; linq练习 有待整理