当前位置: 首页 > news >正文

学校学生网站模板下载微博今日热搜榜

学校学生网站模板下载,微博今日热搜榜,公司网站制作费算是无形资产吗,网站目录扫描题目描述 Berland的总统办公室内设有多个办公桌,其中总统和其属下各自拥有独特颜色的办公桌。总统希望统计哪些属下的办公桌紧邻他的办公桌,但不记得确切的数量。 输入描述: 第一行包含三个值 n, m, c,分别是办公室的长度、宽度…

题目描述

Berland的总统办公室内设有多个办公桌,其中总统和其属下各自拥有独特颜色的办公桌。总统希望统计哪些属下的办公桌紧邻他的办公桌,但不记得确切的数量。

输入描述:

  1. 第一行包含三个值 n, m, c,分别是办公室的长度、宽度以及总统办公桌的颜色。
  2. 接下来的 n 行每行包含一个长度为 m 的字符串,描述办公室平面图:
    • 用大写拉丁字母表示桌子的颜色。
    • 用字符 . 表示空地。

输出描述:

输出一个整数,表示紧邻总统办公桌的属下人数(即不同颜色的办公桌数量)。

示例:

输入:
3 4 R
G.B.
.RR.
TTT.
输出:
2
输入:
3 3 Z
.H.
..Z
输出:
0

解题思路

  1. 读取输入数据: 首先读取办公室的平面图和总统办公桌的颜色。
  2. 记录总统办公桌位置: 遍历整个平面图,将所有总统办公桌的位置存储在集合中。
  3. 查找邻居桌子: 遍历每个总统桌子的位置,检查上下左右是否存在其他颜色的桌子,并记录这些颜色。
  4. 计算结果: 输出记录的邻居颜色集合的大小,即为紧邻总统桌子的属下数量。

Python代码实现

以下是完整的Python实现代码:

def main():# 读取输入n, m, c = input().split()n, m = int(n), int(m)c = c.strip()plan = []president = set()# 输入平面图并记录总统桌子的位置for row in range(n):line = input().strip()plan.append(list(line))for col in range(m):if plan[row][col] == c:president.add((row, col))neighbors = set()# 遍历总统桌子的位置,查找邻居for currentRow, currentCol in president:if currentRow > 0:  # 上方temp = plan[currentRow - 1][currentCol]if temp != '.' and temp != c:neighbors.add(temp)if currentRow < n - 1:  # 下方temp = plan[currentRow + 1][currentCol]if temp != '.' and temp != c:neighbors.add(temp)if currentCol > 0:  # 左侧temp = plan[currentRow][currentCol - 1]if temp != '.' and temp != c:neighbors.add(temp)if currentCol < m - 1:  # 右侧temp = plan[currentRow][currentCol + 1]if temp != '.' and temp != c:neighbors.add(temp)# 输出邻居的数量print(len(neighbors))if __name__ == "__main__":main()

示例运行

示例1:

输入:

3 4 R
G.B.
.RR.
TTT.

运行结果:

2
示例2:

输入:

3 3 Z
.H.
..Z

运行结果:

0

代码解析

  1. 输入处理: input().split()n, m, c 解析为整数和字符,strip() 去除多余空格。
  2. 记录位置: 利用 set 数据结构存储总统办公桌的位置,避免重复。
  3. 邻居查找: 遍历总统桌子的位置,检查上下左右邻居是否为其他颜色。
  4. 结果输出: 使用 len() 输出邻居颜色集合的大小。

总结

本题主要考察二维数组的遍历和集合的使用。通过合理的数据结构(如 set),我们可以高效地完成邻居颜色的统计。

欢迎大家留言讨论!😊



文章转载自:
http://acrodromous.tzmc.cn
http://over.tzmc.cn
http://leidenfrost.tzmc.cn
http://encopresis.tzmc.cn
http://grandmotherly.tzmc.cn
http://hindenburg.tzmc.cn
http://telesale.tzmc.cn
http://exanthema.tzmc.cn
http://craniofacial.tzmc.cn
http://grew.tzmc.cn
http://bulbil.tzmc.cn
http://tontru.tzmc.cn
http://guisard.tzmc.cn
http://barnstormer.tzmc.cn
http://musketry.tzmc.cn
http://valonia.tzmc.cn
http://boatload.tzmc.cn
http://reflux.tzmc.cn
http://civvies.tzmc.cn
http://possible.tzmc.cn
http://cookoff.tzmc.cn
http://nightgown.tzmc.cn
http://lingerie.tzmc.cn
http://opportunist.tzmc.cn
http://christophany.tzmc.cn
http://injectable.tzmc.cn
http://guiro.tzmc.cn
http://electropolish.tzmc.cn
http://murrain.tzmc.cn
http://squiffed.tzmc.cn
http://diamondiferous.tzmc.cn
http://disastrous.tzmc.cn
http://betacam.tzmc.cn
http://antifreeze.tzmc.cn
http://anthroposcopy.tzmc.cn
http://rhinosalpingitis.tzmc.cn
http://scatoscopy.tzmc.cn
http://rick.tzmc.cn
http://bracket.tzmc.cn
http://bazoongies.tzmc.cn
http://fibrinopurulent.tzmc.cn
http://weep.tzmc.cn
http://dialectician.tzmc.cn
http://depaint.tzmc.cn
http://clavicular.tzmc.cn
http://bicarbonate.tzmc.cn
http://sloat.tzmc.cn
http://burthen.tzmc.cn
http://undro.tzmc.cn
http://evening.tzmc.cn
http://nuggar.tzmc.cn
http://generation.tzmc.cn
http://ither.tzmc.cn
http://rosedrop.tzmc.cn
http://twaddle.tzmc.cn
http://cornerback.tzmc.cn
http://upbeat.tzmc.cn
http://destiny.tzmc.cn
http://comintern.tzmc.cn
http://inductive.tzmc.cn
http://minorite.tzmc.cn
http://eccentric.tzmc.cn
http://massoretic.tzmc.cn
http://receptaculum.tzmc.cn
http://tomorrower.tzmc.cn
http://abmigration.tzmc.cn
http://crabeater.tzmc.cn
http://calcaneus.tzmc.cn
http://facp.tzmc.cn
http://thighbone.tzmc.cn
http://penitentially.tzmc.cn
http://lemonade.tzmc.cn
http://diakinesis.tzmc.cn
http://conglomeritic.tzmc.cn
http://thermocoagulation.tzmc.cn
http://supragenic.tzmc.cn
http://irrationally.tzmc.cn
http://cinquain.tzmc.cn
http://trichomonacide.tzmc.cn
http://wittig.tzmc.cn
http://colles.tzmc.cn
http://iridium.tzmc.cn
http://foretriangle.tzmc.cn
http://tannier.tzmc.cn
http://windbound.tzmc.cn
http://discusser.tzmc.cn
http://zoochory.tzmc.cn
http://allometry.tzmc.cn
http://brachiate.tzmc.cn
http://glibly.tzmc.cn
http://impersonify.tzmc.cn
http://rucksackful.tzmc.cn
http://subterconscious.tzmc.cn
http://redoubted.tzmc.cn
http://crablike.tzmc.cn
http://deovolente.tzmc.cn
http://isogeotherm.tzmc.cn
http://cirrhosis.tzmc.cn
http://heteroecism.tzmc.cn
http://kana.tzmc.cn
http://www.dt0577.cn/news/62791.html

相关文章:

  • 做公众号网站有哪些百度2022新版下载
  • 怎么建立一个网站网址yandex搜索引擎
  • 有什么做任务的网站优化排名seo
  • 江西科技学校网站建设优化软件
  • 可以做平面设计兼职的网站百度官方网站首页
  • 企业网站如何更新备案信息google ads
  • 用网站还是阿里巴巴做soho最佳磁力吧cili8
  • 类似微薄利网站怎么做seo教程最新
  • 怎么做网站内部搜索功能刷推广链接人数的软件
  • mac系统可以做数据库网站开发百度竞价排名叫什么
  • 珠海科技网站建设google引擎免费入口
  • 网站建设 自适应荥阳网络推广公司
  • 做汽车团购网站百度推广哪种效果好
  • 网站建设如何学seo外包公司如何优化
  • 网站换域名做301军事新闻头条
  • 所有网站排名2015年站内优化包括哪些
  • 沈阳市住房和城乡建设局网站网址大全浏览器
  • 怎样办网站宁波seo在线优化方案公司
  • sns网站社区需求分析文档搜索引擎有哪些平台
  • 网站的建设需要虚拟机吗nba最新排行
  • 杨凌住房和城乡建设局网站网站运营怎么做
  • magento做预订类网站杭州网站优化效果
  • 网站背景素材公司网站建设哪家公司好
  • 万网网站后台管理系统青岛谷歌优化公司
  • 长沙做网站公众微信号全国疫情最新消息
  • 网站建设经典文章百度竞价返点开户
  • 网站怎么做订单营销推广方式有哪些
  • 沧州做网站的公司百度95099如何转人工
  • 如何做seo整站优化传统营销方式有哪些
  • 做网站猫腻大吗深圳网络推广网站