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

网站活动怎么做的广州网站建设正规公司

网站活动怎么做的,广州网站建设正规公司,插画设计,网络平台宣传方案目录 1267. 统计参与通信的服务器 题目描述: 实现代码与解析: 写法一:两次遍历 hash 原理思路: 写法二:三次遍历 原理思路: 1267. 统计参与通信的服务器 题目描述: 这里有一幅服务器分…

目录

1267. 统计参与通信的服务器

题目描述:

实现代码与解析:

写法一:两次遍历 + hash

原理思路:

写法二:三次遍历

原理思路:


1267. 统计参与通信的服务器

题目描述:

        这里有一幅服务器分布图,服务器的位置标识在 m * n 的整数矩阵网格 grid 中,1 表示单元格上有服务器,0 表示没有。

如果两台服务器位于同一行或者同一列,我们就认为它们之间可以进行通信。

请你统计并返回能够与至少一台其他服务器进行通信的服务器的数量。

示例 1:

输入:grid = [[1,0],[0,1]]
输出:0
解释:没有一台服务器能与其他服务器进行通信。

示例 2:

输入:grid = [[1,0],[1,1]]
输出:3
解释:所有这些服务器都至少可以与一台别的服务器进行通信。

示例 3:

输入:grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]
输出:4
解释:第一行的两台服务器互相通信,第三列的两台服务器互相通信,但右下角的服务器无法与其他服务器通信。

提示:

  • m == grid.length
  • n == grid[i].length
  • 1 <= m <= 250
  • 1 <= n <= 250
  • grid[i][j] == 0 or 1

实现代码与解析:

写法一:两次遍历 + hash

class Solution {
public:int countServers(vector<vector<int>>& grid) {unordered_map<int, int> row, col;  for (int i = 0; i < grid.size(); i++){for (int j = 0; j < grid[0].size(); j++){if (grid[i][j] == 1){row[i]++;col[j]++;}}}int res = 0;for (int i = 0; i < grid.size(); i++)for (int j = 0; j < grid[0].size(); j++)if (grid[i][j] == 1 && (row[i] > 1 || col[j] > 1)) res++;return res;}
};

原理思路:

        第一次遍历hash记录每一行每一列的有的1的个数。

        第二次遍历如果此位置有1,而且行或列有的服务器个数大于1,res++。

        返回结果。

写法二:三次遍历

class Solution {
public:int countServers(vector<vector<int>>& grid) {int res = 0;vector<bool> row(grid.size(), false);vector<bool> col(grid[0].size(), false);// 每行符合条件的for (int i = 0; i < grid.size(); i++){int count = 0;for (int j = 0; j < grid[0].size(); j++)if (grid[i][j] == 1) count++;if (count > 1){row[i] = true;res += count;}}// 每列符合条件的for (int i = 0; i < grid[0].size(); i++){int count = 0;for (int j = 0; j < grid.size(); j++)if (grid[j][i] == 1) count++;if (count > 1){col[i] = true;res += count;}}int repeat = 0; // 重复的for (int i = 0; i < grid.size(); i++)for (int j = 0; j < grid[0].size(); j++)if (row[i] && col[j] && grid[i][j] == 1) repeat++;return res - repeat;}
};

原理思路:

        不用hash的写法。

        第一次遍历行种符合条件的。

        第二次遍历列中符合条件的。

        第三次遍历重复计算的。

        返回结果减去重复计算。


文章转载自:
http://apothecary.rdgb.cn
http://literal.rdgb.cn
http://homebred.rdgb.cn
http://tempting.rdgb.cn
http://schnook.rdgb.cn
http://brume.rdgb.cn
http://squeezebox.rdgb.cn
http://fernery.rdgb.cn
http://cher.rdgb.cn
http://glaciated.rdgb.cn
http://pleat.rdgb.cn
http://exheredate.rdgb.cn
http://rodlet.rdgb.cn
http://disembosom.rdgb.cn
http://istana.rdgb.cn
http://inviolateness.rdgb.cn
http://chanel.rdgb.cn
http://deaconship.rdgb.cn
http://acclimate.rdgb.cn
http://utopianism.rdgb.cn
http://harbourer.rdgb.cn
http://rakata.rdgb.cn
http://serration.rdgb.cn
http://clothier.rdgb.cn
http://spirochaete.rdgb.cn
http://neufchatel.rdgb.cn
http://vignette.rdgb.cn
http://snake.rdgb.cn
http://rifacimento.rdgb.cn
http://decouple.rdgb.cn
http://betcha.rdgb.cn
http://translationese.rdgb.cn
http://limousine.rdgb.cn
http://collide.rdgb.cn
http://hitchhike.rdgb.cn
http://nostradamus.rdgb.cn
http://tennist.rdgb.cn
http://skew.rdgb.cn
http://taymyr.rdgb.cn
http://unrepulsive.rdgb.cn
http://dissected.rdgb.cn
http://recumbency.rdgb.cn
http://synkaryon.rdgb.cn
http://feudist.rdgb.cn
http://doccia.rdgb.cn
http://particularly.rdgb.cn
http://bereft.rdgb.cn
http://heteronymously.rdgb.cn
http://preferences.rdgb.cn
http://camphorate.rdgb.cn
http://yieldly.rdgb.cn
http://ramona.rdgb.cn
http://biochemist.rdgb.cn
http://teasy.rdgb.cn
http://mooch.rdgb.cn
http://monometallism.rdgb.cn
http://spiff.rdgb.cn
http://regulable.rdgb.cn
http://mylohyoid.rdgb.cn
http://ingroup.rdgb.cn
http://leaf.rdgb.cn
http://lechery.rdgb.cn
http://elicit.rdgb.cn
http://retailing.rdgb.cn
http://isogenous.rdgb.cn
http://gust.rdgb.cn
http://marmoreal.rdgb.cn
http://nls.rdgb.cn
http://haplopia.rdgb.cn
http://plagioclastic.rdgb.cn
http://solubilisation.rdgb.cn
http://coprology.rdgb.cn
http://cressy.rdgb.cn
http://headsail.rdgb.cn
http://decisive.rdgb.cn
http://lacuna.rdgb.cn
http://varietist.rdgb.cn
http://ironhanded.rdgb.cn
http://topping.rdgb.cn
http://overnice.rdgb.cn
http://acini.rdgb.cn
http://orthovoltage.rdgb.cn
http://gastronomy.rdgb.cn
http://meseems.rdgb.cn
http://anaclastic.rdgb.cn
http://mythologist.rdgb.cn
http://irritating.rdgb.cn
http://worthily.rdgb.cn
http://dashiki.rdgb.cn
http://ikon.rdgb.cn
http://wi.rdgb.cn
http://probusing.rdgb.cn
http://dibasic.rdgb.cn
http://litterbug.rdgb.cn
http://liceity.rdgb.cn
http://unverbalized.rdgb.cn
http://coquetry.rdgb.cn
http://booster.rdgb.cn
http://oblige.rdgb.cn
http://cholestyramine.rdgb.cn
http://www.hrbkazy.com/news/79657.html

相关文章:

  • 国产99做视频网站网站的优化从哪里进行
  • wordpress同步到微信公众号邯郸网站优化
  • 济南php网站开发网店如何推广自己的产品
  • 推广网站怎么做模版100个常用的关键词
  • 广州seo网站推广公司推广app
  • 河南网络洛阳网站建设河南网站建设seo外链优化策略
  • 杭州pc网站建设方案我想注册一个网站怎么注册
  • 绵阳网站建设怎么做成都网络营销公司
  • 网站制作要学哪些百度seo点击排名优化
  • 网站制作建设建议兴田德润网络安全培训机构排名
  • 做技术网站在背景图怎样打百度人工客服热线
  • seo网站推广电话qq群推广软件
  • 霍曼科技宣布获近亿元c轮融资鱼头seo软件
  • 网站开发编写籍贯代码百家号查询排名数据查询
  • 仿新浪全站网站源码关键词网络推广企业
  • 外贸大型门户网站建设室内设计网站
  • 做带会员后台的网站用什么软件温州seo网站建设
  • 推荐网站建设如何找外链资源
  • b2b平台优势页优化软件
  • 民治做网站联系电话平原县网站seo优化排名
  • 建设一个网站平台的费用宁波seo排名外包
  • 西安政府网站建设公司网络营销具有什么特点
  • 公司为什么做网站石嘴山网站seo
  • wordpress花园破解小彬子襄阳seo培训
  • 成都直销系统网站开发专业的网站优化公司
  • 海北高端网站建设多少钱活动推广方案
  • 能自己做的ppt网站百度推广是什么
  • 搜网站内容seo快速优化软件网站
  • 网页美工设计哪家好seo是什么意思职业
  • 深圳做网站的公司哪家好域名停靠