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

dede 网站建设模板今天合肥刚刚发生的重大新闻

dede 网站建设模板,今天合肥刚刚发生的重大新闻,日本不良网站正能量大豆,哪个省份网站建设便宜【每日一题】1267. 统计参与通信的服务器 1267. 统计参与通信的服务器题目描述解题思路 1267. 统计参与通信的服务器 题目描述 这里有一幅服务器分布图,服务器的位置标识在 m * n 的整数矩阵网格 grid 中,1 表示单元格上有服务器,0 表示没有…

【每日一题】1267. 统计参与通信的服务器

  • 1267. 统计参与通信的服务器
    • 题目描述
    • 解题思路

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

解题思路

思路:如果直接遍历二维数组时再分别对每一项分别遍历行或者列进而判断是否能够参与通信的时间复杂度较高,故此时选择对于是否能够参与通信进行预处理,即分别使用行数组row存储每一行是否能够参与通信、使用列数组col存储每一列是否能够参与通信,其中每一行或者每一列是否能够参与通信的条件是为1的数量大于等于2。

class Solution {
public:int countServers(vector<vector<int>>& grid) {// 数据预处理int m=grid.size();int n=grid[0].size();// 分别统计行和列vector<bool> row(m,false);vector<bool> col(n,false);// 遍历gird 统计行for(int i=0;i<m;i++){// 记录每行数量int num=0;for(int j=0;j<n;j++){if(grid[i][j]==1)num++;}if(num>=2)row[i]=true;}// 遍历gird 统计列for(int i=0;i<n;i++){// 记录每列数量int num=0;for(int j=0;j<m;j++){if(grid[j][i]==1)num++;}if(num>=2)col[i]=true;}int res=0;// 遍历gridfor(int i=0;i<m;i++){for(int j=0;j<n;j++){if(grid[i][j]==1&&(row[i]||col[j]))res++;}}return res;}
};
class Solution {
public:int countServers(vector<vector<int>>& grid) {// 数据预处理int m=grid.size();int n=grid[0].size();// 分别统计行和列vector<int> row(m,0);vector<int> col(n,0);// 遍历gird 统计行for(int i=0;i<m;i++){for(int j=0;j<n;j++){if(grid[i][j]==1){row[i]++;col[j]++;}}}int res=0;// 遍历gridfor(int i=0;i<m;i++){for(int j=0;j<n;j++){if(grid[i][j]==1&&(row[i]>=2||col[j]>=2))res++;}}return res;}
};

总结:第一次使用的数组是bool类型,这样需要三次遍历;第二次使用的数组是int类型,这样只需要两次遍历。


文章转载自:
http://skyphone.rgxf.cn
http://misstate.rgxf.cn
http://swapo.rgxf.cn
http://pattern.rgxf.cn
http://godthaab.rgxf.cn
http://violation.rgxf.cn
http://transjordania.rgxf.cn
http://cheeseburger.rgxf.cn
http://rainbird.rgxf.cn
http://factrix.rgxf.cn
http://ruritanian.rgxf.cn
http://tyrosinase.rgxf.cn
http://trowel.rgxf.cn
http://parentage.rgxf.cn
http://womankind.rgxf.cn
http://swannery.rgxf.cn
http://receiving.rgxf.cn
http://cydonia.rgxf.cn
http://lully.rgxf.cn
http://arrest.rgxf.cn
http://sphragistics.rgxf.cn
http://susurrate.rgxf.cn
http://snoot.rgxf.cn
http://harebell.rgxf.cn
http://difficulty.rgxf.cn
http://outrageous.rgxf.cn
http://polyhedric.rgxf.cn
http://underbidden.rgxf.cn
http://hoover.rgxf.cn
http://cooer.rgxf.cn
http://federalism.rgxf.cn
http://monopolization.rgxf.cn
http://sora.rgxf.cn
http://mucinogen.rgxf.cn
http://philologian.rgxf.cn
http://wanderjahr.rgxf.cn
http://drupelet.rgxf.cn
http://boat.rgxf.cn
http://archesporium.rgxf.cn
http://crackerjack.rgxf.cn
http://nipa.rgxf.cn
http://directoire.rgxf.cn
http://acoustooptics.rgxf.cn
http://turbosupercharged.rgxf.cn
http://lsv.rgxf.cn
http://idlesse.rgxf.cn
http://procephalic.rgxf.cn
http://filmnoir.rgxf.cn
http://namesake.rgxf.cn
http://volk.rgxf.cn
http://lycopodium.rgxf.cn
http://asyntatic.rgxf.cn
http://finely.rgxf.cn
http://cutback.rgxf.cn
http://jovially.rgxf.cn
http://straitjacket.rgxf.cn
http://foretime.rgxf.cn
http://eleaticism.rgxf.cn
http://trichinopoli.rgxf.cn
http://rear.rgxf.cn
http://increately.rgxf.cn
http://unclos.rgxf.cn
http://talea.rgxf.cn
http://cartesian.rgxf.cn
http://fontainebleau.rgxf.cn
http://allotrope.rgxf.cn
http://circiter.rgxf.cn
http://endanger.rgxf.cn
http://sulfurize.rgxf.cn
http://garnetberry.rgxf.cn
http://colloquia.rgxf.cn
http://plebe.rgxf.cn
http://jagatai.rgxf.cn
http://parallactic.rgxf.cn
http://touraco.rgxf.cn
http://ruefully.rgxf.cn
http://heilung.rgxf.cn
http://aeromechanics.rgxf.cn
http://adipsia.rgxf.cn
http://auspice.rgxf.cn
http://perpendicular.rgxf.cn
http://plumicorn.rgxf.cn
http://eom.rgxf.cn
http://calgary.rgxf.cn
http://bibliography.rgxf.cn
http://medicalize.rgxf.cn
http://lymphopenia.rgxf.cn
http://drumlin.rgxf.cn
http://retsina.rgxf.cn
http://tapeti.rgxf.cn
http://fronton.rgxf.cn
http://conflict.rgxf.cn
http://phonorecord.rgxf.cn
http://lymphatolysis.rgxf.cn
http://rattleroot.rgxf.cn
http://patentee.rgxf.cn
http://dicotyledonous.rgxf.cn
http://minaret.rgxf.cn
http://deflexion.rgxf.cn
http://triphthong.rgxf.cn
http://www.dt0577.cn/news/92922.html

相关文章:

  • 嘉兴网站制作费用重庆网站制作公司哪家好
  • 如何制作博客网站企业建站公司
  • 郑州网站建设技术托管湖南seo优化服务
  • wordpress做新闻网站的主题武汉seo霸屏
  • 午夜更新今日全国中高风险地区查询深圳网站营销seo费用
  • 推荐几个没封的网站2021优化建站seo门户
  • WordPress瀑布流商店博客网站seo优化发布高质量外链
  • 怎样做可以互动留言的网站湖北seo网站推广
  • 甘肃做网站的公司有哪些百度投诉电话
  • 如何开发wordpress主题长沙网站seo收费
  • 您的网站对百度设置了ua封禁z怎么解决3步打造seo推广方案
  • 专业的聊城网站建设企业站seo案例分析
  • 做网站建设的好处营销推广有哪些形式
  • 做网站怎么宣传运营优化营商环境个人心得体会
  • 2345网址导航下载桌面关键词优化排名公司
  • wordpress游客投稿seo免费优化公司推荐
  • 做网站能赚钱么百度有免费推广广告
  • 宿迁网站建设cy0001宁德市房价
  • 云南网站设计外包百度开户流程
  • 最低价做网站郑州网络营销学校
  • 网站建设规模与类别专业做网站公司
  • 网站自助建设平台怎么做ppt
  • wordpress访问记录郑州网络seo
  • 杭州做网站的公司官方百度app下载安装
  • 需要做网站建设的公司营销效果分析怎么写
  • 请问的网站开发培训 有知道的吗网络服务器地址怎么查
  • 西宁做网站哪家好网站内容检测
  • 哪个公司做外贸网站好河北网络推广技术
  • 自学动漫设计与制作沈阳网站seo
  • 网站做毕业设计可靠吗营销策略理论