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

电脑做网站软件手机网站优化排名

电脑做网站软件,手机网站优化排名,巨野网站定制,网站中竖导航栏怎么做样例: 解法: 1.遍历矩阵 2.判断矩阵[i][j],若是未标记细胞则遍历相邻所有未标记细胞并标记,且计数 实现:遍历相邻所有未标记细胞 以DFS实现: function dfs(当前状态) {if (终止条件) {}vis[标记当前状…

样例:

解法:

1.遍历矩阵

2.判断矩阵[i][j],若是未标记细胞则遍历相邻所有未标记细胞并标记,且计数

实现:遍历相邻所有未标记细胞

以DFS实现:

function dfs(当前状态) {if (终止条件) {}vis[标记当前状态]for (寻找新状态) {if (状态合法) {dfs(新状态)//看情况是否需要重置vis[]}}
}

代码

#include<iostream>
#include<vector>
using namespace std;
int dir[4][2] = { 0,1,1,0,-1,0,0,-1 };
void dfs(vector<vector<int>>& a, int x, int y) {if (a[x][y] == 0) return;a[x][y] = 0;for (int i = 0; i < 4; i++) {int nextx = x + dir[i][0];int nexty = y + dir[i][1];if (nextx < 0 || nextx >= a.size() || nexty < 0 || nexty >= a[0].size()) {continue;}if (a[nextx][nexty] != 0) {dfs(a, nextx, nexty);}}
}
int main() {int m, n;cin >> m >> n;vector<vector<int>> a(m, vector<int>(n , 0));for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)cin >> a[i][j];int result = 0;for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (a[i][j] != 0) {result++;dfs(a, i, j);}}}cout << result;return 0;
}

以BFS实现:

function bfs(当前节点) {当前节点入列标记当前节点while (队列不为空) {当前节点出列寻找合法相邻节点合法相邻节点入列标记相邻节点}
}

代码:

#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;
int dir[4][2] = { 0,1,1,0,-1,0,0,-1 };
void bfs(vector<vector<int>>& a, int x, int y) {queue<pair<int, int>> que;que.push({ x,y });a[x][y] = 0;while (!que.empty()) {pair<int, int> cur = que.front();que.pop();int curx = cur.first;int cury = cur.second;for (int i = 0; i < 4; i++) {int nextx = curx + dir[i][0];int nexty = cury + dir[i][1];if (nextx < 0 || nextx >= a.size() || nexty < 0 || nexty >= a[0].size()) {continue;}if (a[nextx][nexty] != 0) {que.push({ nextx,nexty });a[nextx][nexty] = 0;}}}
}
int main() {int m, n;cin >> m >> n;vector<vector<int>> a(m, vector<int>(n, 0));for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)cin >> a[i][j];int result = 0;for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (a[i][j] != 0) {result++;bfs(a, i, j);}}}cout << result;return 0;
}

http://www.qdjiajiao.com/news/6015.html

相关文章:

  • 用dw做的网站怎么发布到网上微商软文推广平台
  • 做网站后台数据库建设电商平台的推广及运营思路
  • 空气炸锅做糕点的网站好f123网站
  • 阳春做网站做企业推广
  • 莱芜雪野湖酒店百度搜索引擎优化
  • web个人网站模板企业网站制作费用
  • 中山市城乡和住房建设局网站seo内部优化具体做什么
  • 做一个网站多少费用品牌传播推广方案
  • 工程网络图株洲seo优化
  • 网站后台如何做文件下载连接日照网站优化公司
  • 滇中引水工程建设管理局网站站长工具域名
  • 做影视网站推荐哪个服务器网站注册搜索引擎的目的是
  • 如何在年报网站上做遗失公告怎么做网站关键词优化
  • 东莞网站seo推广技术培训平台
  • 自己做的一个网站怎么赚钱搜索引擎优化搜索优化
  • 网站qq客服制作江苏免费关键词排名外包
  • 网站开发项目经理岗位职责培训网络营销机构
  • 如何安全的做黄色网站佛山关键词排名效果
  • 苏州互联网公司在哪个区seo站长工具是什么
  • 温州企业做网站中国十大营销策划机构
  • 自己做的网站涉黄软件测试培训费用大概多少
  • 盐田高端网站建设seo公司优化排名
  • 网站建站模板地推
  • 手机版网站设计营销推广活动方案
  • wordpress购物车显示龙斗seo博客
  • 网站建设需求分析有什么内容商品推广软文800字
  • 企事业网站建设的毕业论文seo优化与推广招聘
  • 企业营销型网站设计免费建站哪个最好
  • 做电商网站费用软文通
  • 芜湖做公司网站手机网站智能建站