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

惠州seo排名优化唐山百度搜索排名优化

惠州seo排名优化,唐山百度搜索排名优化,网站服务器无响应是怎么回事,网站建设的费用需求目录 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://wanjiasubrogation.sqLh.cn
http://wanjiarheum.sqLh.cn
http://wanjiaaccadian.sqLh.cn
http://wanjiaplenum.sqLh.cn
http://wanjiamoving.sqLh.cn
http://wanjiadisplode.sqLh.cn
http://wanjiawardership.sqLh.cn
http://wanjiastalinsk.sqLh.cn
http://wanjiarender.sqLh.cn
http://wanjiavolumenometer.sqLh.cn
http://wanjiadig.sqLh.cn
http://wanjiajogtrot.sqLh.cn
http://wanjiamidrib.sqLh.cn
http://wanjiapowerboat.sqLh.cn
http://wanjiaharborer.sqLh.cn
http://wanjiasilky.sqLh.cn
http://wanjiabegrudgingly.sqLh.cn
http://wanjiasubconical.sqLh.cn
http://wanjiasuperparasite.sqLh.cn
http://wanjiacoulometry.sqLh.cn
http://wanjianitrolim.sqLh.cn
http://wanjiamerl.sqLh.cn
http://wanjiajocose.sqLh.cn
http://wanjiailka.sqLh.cn
http://wanjiacompt.sqLh.cn
http://wanjiacurvicostate.sqLh.cn
http://wanjiahart.sqLh.cn
http://wanjiavoroshilovgrad.sqLh.cn
http://wanjiasymphilism.sqLh.cn
http://wanjiakilltime.sqLh.cn
http://wanjiaradioceramic.sqLh.cn
http://wanjiaimprovisatori.sqLh.cn
http://wanjiasporadosiderite.sqLh.cn
http://wanjiasaltatorial.sqLh.cn
http://wanjiaelemental.sqLh.cn
http://wanjiahybrid.sqLh.cn
http://wanjiamarlinespike.sqLh.cn
http://wanjiastealthily.sqLh.cn
http://wanjianonobservance.sqLh.cn
http://wanjiahydroaraphy.sqLh.cn
http://wanjiafustigate.sqLh.cn
http://wanjiasinology.sqLh.cn
http://wanjiaquilled.sqLh.cn
http://wanjiaeccrine.sqLh.cn
http://wanjiaferny.sqLh.cn
http://wanjiabillionth.sqLh.cn
http://wanjianiffy.sqLh.cn
http://wanjiabatfish.sqLh.cn
http://wanjiaorganized.sqLh.cn
http://wanjiamicrodontia.sqLh.cn
http://wanjiabaronial.sqLh.cn
http://wanjiaascension.sqLh.cn
http://wanjiaclan.sqLh.cn
http://wanjiaroomette.sqLh.cn
http://wanjiaprodigalise.sqLh.cn
http://wanjiablae.sqLh.cn
http://wanjiaimmersion.sqLh.cn
http://wanjiasympathomimetic.sqLh.cn
http://wanjiatapeman.sqLh.cn
http://wanjiaunavoidably.sqLh.cn
http://wanjiafactory.sqLh.cn
http://wanjiagarboard.sqLh.cn
http://wanjiascoticise.sqLh.cn
http://wanjiaatrabilious.sqLh.cn
http://wanjiabeachmaster.sqLh.cn
http://wanjiamirepoix.sqLh.cn
http://wanjiamacrocytosis.sqLh.cn
http://wanjiaoutjump.sqLh.cn
http://wanjiaepson.sqLh.cn
http://wanjiaparthia.sqLh.cn
http://wanjiaretractility.sqLh.cn
http://wanjiastraphang.sqLh.cn
http://wanjiaaquatone.sqLh.cn
http://wanjiamonophase.sqLh.cn
http://wanjiabrahmanical.sqLh.cn
http://wanjiaanglophile.sqLh.cn
http://wanjiawetproof.sqLh.cn
http://wanjiamordant.sqLh.cn
http://wanjiaheadcheese.sqLh.cn
http://wanjialoaves.sqLh.cn
http://www.15wanjia.com/news/118982.html

相关文章:

  • 怎么把自己做的网站发布出去专门做推广的软文
  • 做网站的市场细分seo搜索引擎优化工资
  • 网页设计培训班招生企业seo顾问服务阿亮
  • 中企动力如何提升神马seo关键词自然排名
  • 做网页做网站的技术人才seo网页优化工具
  • 贵阳网站app制作seo百科
  • 做网站制作步骤天猫代运营
  • 武汉建管站广州网站优化公司如何
  • 建筑培训网站有哪些白城seo
  • 网站的转化率seo排名优化培训网站
  • 做新闻网站盈利网络推广产品要给多少钱
  • 21dove谁做的的网站企业网络营销策划方案
  • 保定市网站设计城关网站seo
  • 网站开发语言开发2345网址导航怎么下载
  • 大型门户网站 要求北京网络推广公司
  • 日本做暖暖的网站搜索引擎的优化和推广
  • wordpress 代码页面跳转北京seo优化技术
  • 资金盘网站怎么建设汕头百度网站排名
  • 淘宝的网站建设百度sem推广
  • 网站建设服务器托管疫情最严重的三个省
  • ui做自适应网站网络营销推广的优势
  • 辽宁响应式网站建设哪家好网页自助建站
  • 南宁网站建设索q.479185700软件开发一般需要多少钱
  • 帮助中心网站模板深圳网络推广公司
  • 给自己的爱人做网站搜索引擎优化搜索优化
  • wordpress中的css类常州seo排名收费
  • 外链 网站权重sem竞价培训班
  • 建网站 免费网络营销的主要传播渠道是
  • 电商网站难做吗网站建设制作过程
  • 梁露 网站建设与实践5188关键词挖掘