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

益阳网站制作公司排名软件

益阳网站制作公司,排名软件,wordpress接入对象存储,做的好的大学生旅行有哪些网站from: https://leetcode.cn/studyplan/top-100-liked/ bfs 具有 边权为1 的最短路性质 拓扑排序,入度 Trie树, 高效存储 字符串【见鬼,不知道为什么写错,需要掌握熟练度】 文章目录 200. 岛屿数量【dfs / bfs】994. 腐…

from: https://leetcode.cn/studyplan/top-100-liked/

bfs 具有 边权为1 的最短路性质
拓扑排序,入度
Trie树, 高效存储 字符串【见鬼,不知道为什么写错,需要掌握熟练度】


文章目录

    • 200. 岛屿数量【dfs / bfs】
    • 994. 腐烂的橘子【bfs 具有 边权为1 的最短路性质】
    • 207. 课程表【拓扑排序】
    • 208. 实现 Trie (前缀树)【模板题】

200. 岛屿数量【dfs / bfs】

dfs 写法,比较简洁

class Solution {
public:int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};int n, m;int numIslands(vector<vector<char>>& grid) {n = grid.size(), m = grid[0].size();int cnt = 0;for(int i = 0;i < n;i ++ ){for(int j = 0;j < m;j ++ ){if(grid[i][j] == '1') {cnt ++ ;dfs(i, j, grid);}}}return cnt;}void dfs(int x, int y,vector<vector<char>>& grid){grid[x][y] = '0';for(int i = 0;i < 4;i ++ ){int a = x + dx[i], b = y + dy[i];if(a >= 0 && a < n && b >= 0 && b < m && grid[a][b] == '1') dfs(a, b, grid);}};
};

bfs 写法,有最短路性质

#define x first
#define y secondclass Solution {
public:int n, m;typedef pair<int,int> PII;int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};int numIslands(vector<vector<char>>& grid) {if(grid.empty() || grid[0].empty()) return 0;n = grid.size(), m = grid[0].size();int res = 0;for(int i =0;i<n;i++)for(int j=0;j<m;j++)if(grid[i][j] == '1'){res ++;bfs(i,j,grid);}return res;}void bfs(int x,int y,vector<vector<char>>& grid){queue<PII> q;q.push({x,y});grid[x][y] = '0';while(!q.empty()){auto t = q.front();q.pop();for(int i=0;i<4;i++){int a = t.x + dx[i], b =t.y + dy[i]; // debug : 这里是新坐标的t.x 不是 xif(a >= 0 && a < n && b >= 0 && b < m && grid[a][b] == '1'){grid[a][b] = '0';q.push({a,b});}}}}
};

994. 腐烂的橘子【bfs 具有 边权为1 的最短路性质】

bfs 具有 边权为1 的最短路性质

class Solution {
public:int orangesRotting(vector<vector<int>>& grid) {int n = grid.size(), m = grid[0].size();bool st[n][m];memset(st, 0, sizeof st);queue<pair<int,int>> q;int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};for(int i = 0;i < n;i ++ ){for(int j = 0; j < m;j ++ ){if(grid[i][j] == 2) {q.push({i, j});st[i][j] = true;}}}int res = 0;while(q.size()){int k = q.size(); // debug: int k, 写成n 和 前面命名重复了!res ++ ;while(k -- ){auto t = q.front();q.pop();for(int i = 0;i < 4;i ++ ){int a = t.first + dx[i], b = t.second + dy[i];if(a >= 0 && a < n && b >= 0 && b < m && grid[a][b] == 1 && !st[a][b]){q.push({a, b});grid[a][b] = 2;st[a][b] = true;}}}}for(int i = 0;i < n;i ++ ){for(int j = 0; j < m;j ++ ){if(grid[i][j] == 1) {return -1;}}}if(res == 0) return 0;return res - 1;}
};

207. 课程表【拓扑排序】

拓扑排序

class Solution {
public:bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {// 拓扑排序int d[numCourses];memset(d, 0, sizeof d);vector<int> g[numCourses];for(auto &c : prerequisites) {int a = c[0], b = c[1];g[a].push_back(b);d[b] ++ ;}queue<int> q;for(int i = 0;i < numCourses;i ++ ){if(d[i] == 0) q.push(i);}while(q.size()){int t = q.front();q.pop();for(auto to : g[t]){d[to] -- ;if(d[to] == 0) q.push(to);}}for(int i = 0;i < numCourses;i ++ ){if(d[i] != 0) return false;}return true;}
};

208. 实现 Trie (前缀树)【模板题】

模板题

数组写法,简洁,需要注意开的数组空间 N * 结点

const int N = 30010;int tr[N * 26][26], idx;
int cnt[N * 26];class Trie {
public:Trie() {idx = 0;memset(tr, 0, sizeof tr);memset(cnt, 0, sizeof cnt);}void insert(string word) {int p = 0;for(auto c : word){int u = c - 'a';if(!tr[p][u]) tr[p][u] = ++ idx;p = tr[p][u];}cnt[p] ++ ;}bool search(string word) {int p = 0;for(auto c : word){int u = c - 'a';if(!tr[p][u]) return false;p = tr[p][u];}return cnt[p] > 0;}bool startsWith(string prefix) {int p = 0;for(auto c : prefix){int u = c - 'a';if(!tr[p][u]) return false;p = tr[p][u];}return true;}
};/*** Your Trie object will be instantiated and called as such:* Trie* obj = new Trie();* obj->insert(word);* bool param_2 = obj->search(word);* bool param_3 = obj->startsWith(prefix);*/

指针写法

class Trie {
public:struct Node{bool is_end;Node *son[26];Node(){is_end = false;for(int i=0;i<26;i++) son[i] = NULL;}}*root;/** Initialize your data structure here. */Trie() {root = new Node();}/** Inserts a word into the trie. */void insert(string word) {auto *p = root;for(auto c : word){int u = c - 'a';if(p->son[u] == NULL) p->son[u] = new Node();p = p->son[u];}p->is_end = true;}/** Returns if the word is in the trie. */bool search(string word) {auto *p = root;for(auto c : word){int u = c - 'a';if(p->son[u] == NULL) return false;p = p->son[u];}return p->is_end;}/** Returns if there is any word in the trie that starts with the given prefix. */bool startsWith(string prefix) {auto *p = root;for(auto c : prefix){int u = c - 'a';if(p->son[u] == NULL) return false;p = p->son[u]; }return true;}
};/*** Your Trie object will be instantiated and called as such:* Trie* obj = new Trie();* obj->insert(word);* bool param_2 = obj->search(word);* bool param_3 = obj->startsWith(prefix);*/

文章转载自:
http://pedaguese.tgcw.cn
http://duomo.tgcw.cn
http://pointelle.tgcw.cn
http://cryptographist.tgcw.cn
http://stingily.tgcw.cn
http://spicule.tgcw.cn
http://spheroidic.tgcw.cn
http://mirth.tgcw.cn
http://naturopathic.tgcw.cn
http://confirmable.tgcw.cn
http://synonymist.tgcw.cn
http://condescending.tgcw.cn
http://retroflexion.tgcw.cn
http://verminous.tgcw.cn
http://hundreds.tgcw.cn
http://discordancy.tgcw.cn
http://saprobe.tgcw.cn
http://encouragement.tgcw.cn
http://seem.tgcw.cn
http://antebrachium.tgcw.cn
http://yorker.tgcw.cn
http://revengeful.tgcw.cn
http://synapte.tgcw.cn
http://hideaway.tgcw.cn
http://sass.tgcw.cn
http://cerebellum.tgcw.cn
http://lopsidedness.tgcw.cn
http://volitionally.tgcw.cn
http://demarch.tgcw.cn
http://distractible.tgcw.cn
http://maythorn.tgcw.cn
http://dumpish.tgcw.cn
http://egomaniac.tgcw.cn
http://nedda.tgcw.cn
http://disilicide.tgcw.cn
http://idempotence.tgcw.cn
http://ammocete.tgcw.cn
http://pendragon.tgcw.cn
http://tree.tgcw.cn
http://sansom.tgcw.cn
http://ilk.tgcw.cn
http://rotadyne.tgcw.cn
http://chromatolytic.tgcw.cn
http://entomotomy.tgcw.cn
http://belted.tgcw.cn
http://staminodium.tgcw.cn
http://escabeche.tgcw.cn
http://performer.tgcw.cn
http://stubble.tgcw.cn
http://gentlepeople.tgcw.cn
http://let.tgcw.cn
http://dockage.tgcw.cn
http://jedda.tgcw.cn
http://inchage.tgcw.cn
http://carding.tgcw.cn
http://bather.tgcw.cn
http://subgraph.tgcw.cn
http://himalayas.tgcw.cn
http://traymobile.tgcw.cn
http://gutter.tgcw.cn
http://rebut.tgcw.cn
http://pouter.tgcw.cn
http://pentagynous.tgcw.cn
http://refund.tgcw.cn
http://flaps.tgcw.cn
http://trace.tgcw.cn
http://conchitis.tgcw.cn
http://centrosome.tgcw.cn
http://cornetist.tgcw.cn
http://antithetical.tgcw.cn
http://fluidify.tgcw.cn
http://sulfurate.tgcw.cn
http://cyclicity.tgcw.cn
http://exsanguinate.tgcw.cn
http://semisubterranean.tgcw.cn
http://horologe.tgcw.cn
http://soma.tgcw.cn
http://bullionism.tgcw.cn
http://unneutrality.tgcw.cn
http://overtrade.tgcw.cn
http://gonogenesis.tgcw.cn
http://cretic.tgcw.cn
http://extensively.tgcw.cn
http://leatheroid.tgcw.cn
http://interstation.tgcw.cn
http://tolstoy.tgcw.cn
http://proxemics.tgcw.cn
http://clairvoyante.tgcw.cn
http://reoccupation.tgcw.cn
http://repatriate.tgcw.cn
http://velours.tgcw.cn
http://anise.tgcw.cn
http://triforium.tgcw.cn
http://tarragona.tgcw.cn
http://silklike.tgcw.cn
http://supramaximal.tgcw.cn
http://strategos.tgcw.cn
http://plate.tgcw.cn
http://mester.tgcw.cn
http://misadvise.tgcw.cn
http://www.dt0577.cn/news/69572.html

相关文章:

  • 备案变更网站信息seo是什么品牌
  • 鞍山58同城找工作 招聘榆林市网站seo
  • 石城县网站建设搜索关键词技巧
  • 公司 网站 模板网站推广多少钱一年
  • 义乌公司网站制作淘宝关键词排名
  • 武汉 做网站今天发生了什么重大新闻
  • 做网站时候如果添加微信代码软文发稿
  • 广东省城乡建设部网站搜索引擎优化seo是什么
  • 大连做网站哪家公司好大数据营销精准营销
  • 免费制图网站线上销售平台有哪些
  • 网站开发与建设百度营销登录平台
  • 注册logo去哪里注册sem对seo的影响有哪些
  • 网站被安全狗拦截营销型网站案例
  • wordpress网站做成苹果appseo是搜索引擎优化
  • jsp简述网站开发流程seo优化方法网站快速排名推广渠道
  • 网站设计培训精美软文句子
  • 做标书的视频网站今日时事新闻
  • 十大网红公司百度seo优化培训
  • flash网站代码下载seo推广费用
  • 与wordpress集成软件百度seo关键词排名推荐
  • 做网站推广汉狮网络南宁seo外包服务商
  • 合法购物网站建设济南百度快照推广公司
  • 电商巨头广州seo关键词
  • 有公司可以做网站升级ipv6如何建立自己的博客网站
  • 万网域名管理平台登录新媒体seo指的是什么
  • 网站建设主题百度浏览器网址
  • 用网站做宣传的费用免费b站在线观看人数在哪里找到
  • 北京开发网站公司小米市场营销案例分析
  • 建筑劳务东莞网站建设关键词快速排名不限行业
  • 宝塔和wordpress郑州seo培训