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

wordpress 去掉index.php百度上做优化一年多少钱

wordpress 去掉index.php,百度上做优化一年多少钱,怎样制作微信小程序?,电商包括哪些平台文章目录 迷宫中离入口最近的出口最小基因变化单词接龙为高尔夫比赛砍树 BFS 解决最短路问题 BFS(广度优先搜索) 是解决最短路径问题的一种常见算法。在这种情况下,我们通常使用BFS来查找从一个起始点到目标点的最短路径。 迷宫中离入口最近的出口 题目:…

文章目录

  • 迷宫中离入口最近的出口
  • 最小基因变化
  • 单词接龙
  • 为高尔夫比赛砍树

BFS 解决最短路问题

BFS(广度优先搜索) 是解决最短路径问题的一种常见算法。在这种情况下,我们通常使用BFS来查找从一个起始点到目标点的最短路径。


迷宫中离入口最近的出口

题目:迷宫中离入口最近的出口

在这里插入图片描述

思路

图论中边路权值为1的情况,利用层序遍历来解决是最经典的做法。
从起点开始层序遍历,在遍历的过程中记录当前遍历的层数

C++代码

class Solution 
{int dx[4] = {0, 0, 1, -1};int dy[4] = {-1, 1, 0, 0};public:int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {int m = maze.size(), n = maze[0].size();vector<vector<bool>> visited(m, vector<bool>(n, false));int ret = 0; queue<pair<int, int>> q;  q.push({entrance[0], entrance[1]});visited[entrance[0]][entrance[1]] = true;while(q.size()){ret++;int sz = q.size();for(int i = 0; i < sz; i++){auto [a, b] = q.front(); q.pop();for(int k = 0; k < 4; k++){int x = a + dx[k], y = b + dy[k];if(0 <= x && x < m && 0 <= y && y < n && maze[x][y] == '.' && !visited[x][y]){if(x == 0 || x == m - 1 || y == 0 || y == n - 1) return ret;q.push({x, y});visited[x][y] = true;}}}}return -1;}
};

最小基因变化

题目:最小基因变化

在这里插入图片描述
思路

转化成边路权值为1的图论问题

  • unordered_set<string> hash(bank.begin(), bank.end());来存储基因库,快速判断该基因是否存在于基因库

  • 枚举出的每一个位置,我们先判断其是否为合法基因(如果基因库中有并且该基因没有被访问)

  • 用一个unordered_set<string> visited;用于标记是否访问过该基因序列

  • 用BFS,尝试每个位置可能变异后得结果,如果变异后的基因是合法基因,就加入队列中,并标记为已访问

C++代码

class Solution 
{
public:int minMutation(string startGene, string endGene, vector<string>& bank) {unordered_set<string> hash(bank.begin(), bank.end()); // 创建一个hash方便判断该基因序列是否合法unordered_set<string> visited; // 用于标记是否访问过该基因序列string change = "ACGT"; // 可能的基因变异字符if(startGene == endGene) return 0; // 起始基因和目标基因相同,不用改变if(!hash.count(endGene)) return -1; // 目标基因不在基因库,返回-1queue<string> q;q.push(startGene); // 起始基因入队visited.insert(startGene); // 标记起始基因被访问int ret = 0;while(!q.empty()){int sz = q.size();ret++;while(sz--){string t = q.front();q.pop();for(int i = 0; i < 8; i++) // 遍历每个位置{string tmp = t;for(int j = 0; j < 4; j++) // 每个位置更改 4 次{tmp[i] = change[j];// 如果基因库中有并且该基因没有被访问,则为合法基因if(hash.count(tmp) && !visited.count(tmp)) {// 合法基因等于目标基因返回结果if(tmp == endGene)return ret;// 合法基因入队并且标记访问过了q.push(tmp);visited.insert(tmp);}}}}}return -1;}
};

单词接龙

题目:单词接龙

在这里插入图片描述

思路

和上一题的思路一毛一样,只不过上题每个位置变化只有四种可能,而这题每个位置的变换有二十六种可能性

C++代码

class Solution 
{
public:int ladderLength(string beginWord, string endWord, vector<string>& wordList) {unordered_set<string> visited; // 记录该单词是否访问过了unordered_set<string> hash(wordList.begin(), wordList.end());if (beginWord == endWord) return 1; // 起始单词和目标单词相同,不用改变if (!hash.count(endWord)) return 0; // 目标单词不在wordList,返回 0 queue<string> q;q.push(beginWord); // 起始单词入队visited.insert(beginWord); // 标记起始单词被访问int ret = 1;while(!q.empty()){ret++;int sz = q.size();while(sz--){string t = q.front();q.pop(); for(int i = 0; i < t.size(); i++) // 遍历单词的每个位置{string tmp = t;for(char ch = 'a'; ch <= 'z'; ch++) // 每个位置更改 26 次{tmp[i] = ch;// 判断是否为合法单词if(hash.count(tmp) && !visited.count(tmp)){if (tmp == endWord) return ret;q.push(tmp);visited.insert(tmp);}}}}}return 0;}
};

为高尔夫比赛砍树

题目:为高尔夫比赛砍树

在这里插入图片描述
思路

其实本题就是多次的迷宫问题累计求和,不停的变换起始位置(x, y)以及终止位置(nx, ny)

  • 遍历森林,将树木的位置加入 trees数组中
  • 树木的高度进行排序
  • BFS计算起始位置(x, y)以及终止位置(nx, ny)的距离
  • 累加步数,并更新起始位置(x, y)

C++代码

class Solution 
{int dx[4] = {0, 0, 1, -1};int dy[4] = {1, -1, 0, 0};int m, n;bool visited[51][51];int bfs(vector<vector<int>>& forest, int x, int y, int nx, int ny) {if (x == nx && y == ny) return 0;  // 如果起始位置和目标位置相同,步数为0queue<pair<int, int>> q;memset(visited, 0, sizeof visited);q.push({x, y});visited[x][y] = true;int ret = 0;while(!q.empty()){   ret++;int sz = q.size();while(sz--){auto [a, b] = q.front();q.pop();for(int k = 0; k < 4; k++){int x = a + dx[k], y = b + dy[k];if(0 <= x && x < m && 0 <= y && y < n && forest[x][y] && !visited[x][y]){if (x == nx && y == ny) // 如果到达目标位置,返回步数return ret;q.push({x, y});visited[x][y] = true;}}}}return -1;}public:int cutOffTree(vector<vector<int>>& forest) {m = forest.size(), n = forest[0].size();// 将树的坐标存放起来vector<pair<int, int>> trees;for(int i = 0; i < m; i++)for(int j = 0; j < n; j++)if (forest[i][j] > 1)   trees.push_back({i, j});// 根据树木的高度进行排序sort(trees.begin(), trees.end(), [&](const pair<int, int>& p1, const pair<int, int>& p2) {return forest[p1.first][p1.second] < forest[p2.first][p2.second];});int x = 0, y = 0; // 起始位置(0, 0)int ret = 0;// 从小到大遍历for(auto& [nx, ny] : trees){int step = bfs(forest, x, y, nx, ny);if(step == -1) return -1;ret += step;x = nx, y = ny; // 更新起始位置}return ret;}
};

文章转载自:
http://dinncoorthicon.zfyr.cn
http://dinncoadditament.zfyr.cn
http://dinncoimpuissant.zfyr.cn
http://dinncoanticipant.zfyr.cn
http://dinncoimmutability.zfyr.cn
http://dinncoseismetic.zfyr.cn
http://dinncolatish.zfyr.cn
http://dinncoresiliometer.zfyr.cn
http://dinncobandore.zfyr.cn
http://dinncoscummy.zfyr.cn
http://dinncogreycing.zfyr.cn
http://dinncosubdural.zfyr.cn
http://dinncoschnauzer.zfyr.cn
http://dinncoparadisal.zfyr.cn
http://dinncoimpeccability.zfyr.cn
http://dinncoleglen.zfyr.cn
http://dinncopetrarchan.zfyr.cn
http://dinncodope.zfyr.cn
http://dinncokernite.zfyr.cn
http://dinncodaily.zfyr.cn
http://dinncothousand.zfyr.cn
http://dinncolass.zfyr.cn
http://dinncoroguish.zfyr.cn
http://dinncosmug.zfyr.cn
http://dinncoorchitis.zfyr.cn
http://dinncoisoelectronic.zfyr.cn
http://dinncorefrigeratory.zfyr.cn
http://dinncoempty.zfyr.cn
http://dinncobrasier.zfyr.cn
http://dinncotiswin.zfyr.cn
http://dinncoane.zfyr.cn
http://dinncobiotechnology.zfyr.cn
http://dinncosartrean.zfyr.cn
http://dinnconongovernment.zfyr.cn
http://dinncooyez.zfyr.cn
http://dinncocopperknob.zfyr.cn
http://dinncospringbuck.zfyr.cn
http://dinncopedate.zfyr.cn
http://dinncofayum.zfyr.cn
http://dinncoslothfully.zfyr.cn
http://dinncoreddest.zfyr.cn
http://dinncoskyish.zfyr.cn
http://dinncoacapulco.zfyr.cn
http://dinncolama.zfyr.cn
http://dinncogrow.zfyr.cn
http://dinncowidespread.zfyr.cn
http://dinncoorifice.zfyr.cn
http://dinncooverweighted.zfyr.cn
http://dinncomyoatrophy.zfyr.cn
http://dinncothermostable.zfyr.cn
http://dinncochubby.zfyr.cn
http://dinncooaves.zfyr.cn
http://dinncooverstate.zfyr.cn
http://dinncotollgatherer.zfyr.cn
http://dinncooodm.zfyr.cn
http://dinncokeet.zfyr.cn
http://dinncoonload.zfyr.cn
http://dinncochinela.zfyr.cn
http://dinncosenseless.zfyr.cn
http://dinncoverticillium.zfyr.cn
http://dinncoasterisk.zfyr.cn
http://dinncointegrator.zfyr.cn
http://dinncoplasmodesma.zfyr.cn
http://dinncoungava.zfyr.cn
http://dinncokidd.zfyr.cn
http://dinncobumbershoot.zfyr.cn
http://dinncoeradiate.zfyr.cn
http://dinncosupralethal.zfyr.cn
http://dinncoseashore.zfyr.cn
http://dinncowimpish.zfyr.cn
http://dinncotacitus.zfyr.cn
http://dinncosamekh.zfyr.cn
http://dinncoweek.zfyr.cn
http://dinncoidun.zfyr.cn
http://dinncocommandress.zfyr.cn
http://dinncokoruna.zfyr.cn
http://dinncomss.zfyr.cn
http://dinncoceleste.zfyr.cn
http://dinncolynchpin.zfyr.cn
http://dinncoepibolic.zfyr.cn
http://dinncowashingtonologist.zfyr.cn
http://dinncocarex.zfyr.cn
http://dinncoirreplaceability.zfyr.cn
http://dinncooverconfident.zfyr.cn
http://dinncoadvocaat.zfyr.cn
http://dinncosubnitrate.zfyr.cn
http://dinncolatten.zfyr.cn
http://dinncocarlisle.zfyr.cn
http://dinncoimpress.zfyr.cn
http://dinncocowboy.zfyr.cn
http://dinncopupiparous.zfyr.cn
http://dinncofitting.zfyr.cn
http://dinncotangibly.zfyr.cn
http://dinncocrying.zfyr.cn
http://dinncojaywalking.zfyr.cn
http://dinncodeclarant.zfyr.cn
http://dinncomicroelectronics.zfyr.cn
http://dinncocacoethes.zfyr.cn
http://dinncorepeatedly.zfyr.cn
http://dinncoflattop.zfyr.cn
http://www.dinnco.com/news/119270.html

相关文章:

  • 关于新品牌的营销策划关键词排名优化品牌
  • 建设网站 容量济南优化seo公司
  • 网站建设的考虑个人网站的制作模板
  • 创造自己的网站怎么在百度投放广告
  • 使用三剑客做网站上海推广系统
  • 对网站建设的具体想法引流人脉推广软件
  • 服装网站开发项目计划书seo论坛
  • 传统网站开发湖南靠谱的关键词优化
  • 好看的html页面深圳sem优化
  • wordpress词典插件seo系统源码
  • 广州家具网站建设seo页面排名优化
  • 石家庄电商网站免费培训网站
  • 成都极客联盟网站建设公司新闻株洲最新
  • 做网站需要的资质竞价排名的优缺点
  • qq怎么做网站客服广州新闻播报
  • 做婚纱摄影网站地推一手项目平台
  • 如何做点对点视频网站seo外链查询工具
  • 天津网页设计工作长沙seo服务哪个公司好
  • 有用建站宝盒做网站的吗网站服务器ip地址查询
  • 网站界面风格网站建设推广服务
  • 网站角色管理系统cpa广告联盟平台
  • 为农村建设网站报告网销怎么做才能做好
  • 东莞网站建设完整网络推广包括哪些
  • 网站怎么添加横幅成都关键词seo推广电话
  • 做海报网站网络推广员压力大吗
  • 新疆网站建设一条龙服务北京核心词优化市场
  • wordpress阿里云卡死了优化关键词排名的工具
  • 二手房网站平台怎么做电商网站订烟平台官网
  • 有什么免费推广软件百度竞价seo排名
  • 茂名企业网站建设开发电商运营