Gym - 101246B 3D City Model

【Qt串口调试助手】1.1 - Qt5编写串口调试助手,Qt串口编程 这章来学习串口数据流操作。仿照成品制作一个自己用Qt编写的串口助手。 1. 布局UI界面 创建QWidget工程,布局UI界面:拖入2个 Plain Text Edit,作为串口数据的接收显示和发送框。 拖入几个 Combo Box 、Label 和 Push Button,使用两个Widget进行布局。如下所示。 将接收区的 Plain Text Edit,属性勾选上 readOnly,使其运行时不会被人为的输入操作影响。 加入一些弹簧,使布局美观。(有必要可以加设置不能调整.. 阅读详情
A题来自codeforces上的一题  原题地址
B. 3D City Model
time limit per test
1.0 s
memory limit per test
256 MB
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 3
111
212
111
output
38
input
3 4
1000
0010
0000
output
12
Note

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

大致题意就是 给出立方体的形状 求该几何体的表面积

我的思想是 (1)每次读入矩阵的时候 同时计数有多少个小立方体  记为sum

                   (2)用for循环去判断小立方体之间重合的有多少块  (三个方向都要判断) 记为ans

                   (3)运用数学公式  sum*6-ans*2 (每个小立方体的基础面积为6  一块重合面积使两方都各少一块)

下面放一下代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int x[1005][1005];
char y[1005][1005];
int main()
{
    int m,n;
    char a;
    int sum=0;
    int ans=0;
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cin >> n >> m;
    memset(x,0,sizeof x);
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)//读入矩阵
        {
            cin>>a;
            a-='0';
            x[i][j]=a;
        }
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)//对小方块进行计数
        {
            sum=sum+x[i][j];
        }
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)//横向 如果有重合部分就计数
        {
            ans+=min(x[i][j],x[i][j+1]);//重合部分算两者中小的面积
        }
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
        {
            ans+=min(x[i+1][j],x[i][j]);
        }
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
            if (x[i][j]>1)
                ans+=(x[i][j]-1);//高度大于1时 竖直方向的重合部分 为高度减一
    int h=sum*6-ans*2;//每一块基础表面积为6 减去重合部分的 *2
    cout << h <<endl;
    return 0;
}
前一次交题的时候卡在 test 10 
想了好久不知道错哪里了
后来 一个学长给了一个他的样例 
我测试了一下 发现...我的行列标记反了 唉( ̄m ̄)
以后 再遇到矩阵题目要注意一下了...
值得苦练的100道Python经典练手题(全网最全,附详细答案,建议收藏) 这100道Python练习题涵盖了从基础语法到高级算法、从数据库操作到Web开发的各个方面,是备考数据库系统工程师的绝佳素材。建议按照章节顺序逐一练习,遇到难点可反复钻研,真正掌握每一道题背后的知识点。通过这些练习,不仅能提升Python编程能力,还能加深对数据库系统原理的理解,为考试和实际工作打下坚实基础。 阅读详情

相关推荐

在win10系统上安装opnet14.5注意事项和步聚

opnet 14.5安装避坑!

miracle_eicont的专栏 1037

B - 3D City Model

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 ...

七九河开的博客 470

FFmpeg魔改指南:让RTMP协议完美兼容H265的三种方法(含SRS适配技巧)

本文详细介绍了三种让RTMP协议兼容H265编码的FFmpeg魔改方案,包括基于官方补丁的标准改造、Intel的SVT-HEVC集成方案以及金山云的自定义扩展方案。文章重点解析了各方案的实现原理与适配技巧,并提供了在SRS 6.0服务器上进行深度配置和性能调优的完整实战指南,帮助开发者解决H265推流至传统RTMP服务器的兼容性问题。

weixin_29290947的博客 195

Gym 101246(ACM ICPC 2010-2011, NEERC, Southern Subregional Contest Russia, Saratov)

PROBLEM B D ARE INCLUDED(E F are planned) Problem B. 3D City Model 题意:         用积木搭成 N * M 的物体,并给出每块的高度求表面积。 思路:         对于每一块区域,有基础面积 4 * H + 2         再分别减去与上下左右的重合面积(两个区域的最小高度) 代码: #inclu

DT2131 1075

Windows下ArduPilot SITL仿真环境搭建与QGC地面站联调全攻略

软件在环仿真(SITL)是无人机开发中的关键一环,它通过将飞控固件运行在PC上,用数学模型模拟传感器数据,实现无硬件依赖的飞行逻辑验证。这项技术不仅降低了试错成本,更为地面站开发、自动化测试和任务规划提供了安全可控的试验场。在工程实践中,MAVLink协议作为飞控与地面站之间的通信桥梁,贯穿仿真、遥测与指令控制全程。结合QGroundControl(QGC)这一主流地面站,开发者可以直观地观察飞行状态、规划航点并记录日志。本文以Windows原生环境为例,详细介绍ArduPilot SITL的搭建流程、MA

weixin_31858171的博客 317

keil软件调试(Debug)仿真教程(软件调试和硬件调试的区别)及常用调试按键详解

单片机的调试分为两种,一种是使用软件模拟调试,第二种是硬件调试,两种调试方式各有不同,软件模拟调试有误差,而硬件调试,借用仿真器调试是嵌入式开发中常用方法。

weixin_51624736的博客 3万+

2018深圳杯数学建模A题

  做的还不是很完善,还请大家多多提意见 2018思特奇杯数学建模竞赛题目 (请严格遵守对论文格式的统一要求)   A题-人才吸引力评价模型研究       在世界各国和全国各地都加大争夺人才的背景下,一个城市要保持其竞争活力和创新力,必须与时俱进地但不盲目地调整相关人才吸引政策。2018年深圳市将加大营商环境改革力度作为一项重要工作,以吸引更多优秀的高新企业和优秀的人才。    吸...

Tyella的博客 23万+

射频工程师必须了解的S参数四项要点

本文围绕单端 6 英寸走线的 S 参数展开深入分析,核心包含四项关键要点:低频下导线电学长度远小于信号波长,S11 呈大负分贝值、S21 接近 0 分贝;端口与走线的阻抗不匹配引发反射叠加,形成 S11 首个峰值(对应传输线四分之一波长频率);S21 相位可作为一致性检查依据,其 90° 相位差与 S11 峰值吻合;理想建模中 S11 峰值随频率上升因损耗下降,实际测量因连接器等阻抗不连续性,S11 会出现振荡上升。分析依托 Keysight ADS 工具与电磁求解器原理,为 S 参数解读提供科学支撑。

一只豌豆象的博客 1284

SGU - 519 - 3D City Model (模拟)

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 t

Never say never 770

抖音 webmssdk 签名算法解析:X-Dynosaur / X-Gnarly / X-Bogus 生成原理

它只依赖设备指纹/环境编码与随机数,与 query 内容无关,因此可以独立于 Dynosaur/Gnarly 生成。

猫敷雪 197

q-learning精讲

Q-learning Q-learning是一种用于机器学习的强化学习技术。 Q-learning的目标是学习一种策略,告诉Agent在什么情况下要采取什么行动。 它不需要环境模型,可以处理随机转换和奖励的问题,而无需进行调整。 对于任何有限马尔可夫决策过程(FMDP),Q学习找到一种最优的策略,即从当前状态开始,它在任何和所有后续步骤中最大化总奖励的预期值。在给定无限探索时间和部分随机策略的情况...

weixin_41697507的博客 1万+

CF:3D City Model(小思维)

链接: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 ...

weixin_33798152的博客 221

Claude Code Skills 入门:内置技能与自定义技能开发

│ Skill 的特点 │1. 封装性:把复杂操作封装成简单命令2. 可复用:一次定义,随处使用3. 可定制:支持参数传入4. 可发现:通过 /skill-name 方式调用打个比方,如果说 Claude Code 的基础工具是「原材料」,那 Skills 就是「预制菜」——只需要简单加热(调用),就能得到成品(结果)。你可以创建自己的 Skill 来封装常用操作。Skill 支持参数,通过。

gaoxiang_120的专栏 670

sgu 519. 3D City Model

519. 3D City ModelTime limit per test: 0.25 second(s)Memory limit: 262144 kilobytesinput: standardoutput: standardA city is built on the top of a rectangular n x m grid where all the grid cells are eq...

superkunn的博客 223

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

sgu - 519 - 3D City Model

题意:给出一个n*m的矩阵,也是由1*1*1的小立方体组成的几何体的俯视图,求这个几何体的表面积(1 题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=519 ——>>原想分角、边、中间3部分求,不过写着写着即发现,自己想复杂啦,可以不分类,一起求。 对于矩阵中的每一个元素,求与其上、下、左、右的高度差,这个差值就是能看见的正侧面,求

无节操 1404

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Gym - 101246A Bencoding【模拟】

题目链接:https://vjudge.net/problem/Gym-101246A 题意:有三种形式的变量,分别为 整数:i数字e,字符串:字符串长度n:n个字符,列表:l列表内容e,字典:d字典内容e,注意整数中间不能出现其他的字符,也不能有前导零,也不能为负数,列表里面可以出现列表也可以出现整数和字符,字典里面的key可以重复,字典和列表都可以充当key和value,首先判断给出的字符串

22h's Blog 571

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Polya定理及例题

概念 先讲Burnside定理: 百度百科的传送门:https://baike.baidu.com/item/burnside%E5%BC%95%E7%90%86/1505996  再放一个例题:    重点还是Polya定理 百度百科的传送门:https://baike.baidu.com/item/Polya/11020869 Polya定理在Burnside定...

OneLine_的博客 8674

2019湖北省省赛 D题题解

湖北省网络赛D题题解 D. Dandelion time limit per test 1.0 s memory limit per test 256 MB input standard input output standard output "O dandelion, yellow as gold, What do you do all day?" "I just wa...

OneLine_的博客 1015

Gym 101028C A or B Equals C

原题地址:http://codeforces.com/gym/101028/problem/CRami went back from school and he had an easy homework about bitwise operations (and,or,..) The homework was like this : You have an equation : " A | B =...

OneLine_的博客 833

鸽巢定理和容斥定理 (POJ 2356 、POJ 3370 + HDU 1796)

  真的好久没写博客了 之前是考试周就没怎么做题 后来考试后回家 去厦门玩耍了三四天 19号回学校 20号开始集训 emmmm 结束碎碎念 开始进入正题吧~   目录 鸽巢定理: POJ  2356 POJ  3370 &amp;&amp; HDU 1808 容斥定理: HDU 1796 鸽巢定理: 也叫 抽屉定理, 抽屉原理的一般含义为:“如果每个抽屉代表一个集合,每...

OneLine_的博客 614

HDU 6216 (2017icpc青岛网络赛)

A Cubic number and A Cubic Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2478    Accepted Submission(s): 1015   Problem Description ...

OneLine_的博客 507

CSU - 2135 Appositive Body

当时在现场赛的时候 学长说这题可以做做看因为其他队伍有马上AC的 但是是全英文的,又不是很理解,只能说了解了一个大概吧......DescriptionYuki Nagato is an alien created by the Data Overmind, and possesses supernatural powers as a result. Two of her abilities ar...

OneLine_的博客 400

HDU 6665 离散化 + dfs OR 用交集矩形求分块

2019暑期多校第八场1009 两种方法解决 离散化+dfs 或者 用交集矩形求分块

OneLine_的博客 388

CSU 2164 2018 组合数

CSU 21642018 组合数 在省赛之前看看往届的题目,做题的时候有想到种类相乘,但是没有写... 补题的时候看了许多大佬的题解也没有完全理解 所以 差不多理解了之后写一下博客 参考:https://blog.youkuaiyun.com/a465798176/article/details/89947130 https://blog.youkuaiyun.com/songziqi98/article/d...

OneLine_的博客 366

CSU - 2130 Permutations

周日 毫无准备地被拉去打了一场现场赛书包里装的是

OneLine_的博客 358
下一篇: CSUFT OJ 1142 及 1141
OneLine_
博客等级 码龄9年 48粉丝 72原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值