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

韶关手机网站建站运营一般一个月多少钱

韶关手机网站建站,运营一般一个月多少钱,网站实名认证要钱吗,一级域名生成二级域名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://www.yayakq.cn/news/261105/

相关文章:

  • 户网站开发的小公司怎么做链接有图和文字
  • 电脑什么软件可以做动漫视频网站点击出字插件wordpress
  • 会员充值网站怎么做拖拽自助建站系统源码
  • 茂名网站制作计划国际外贸网络交易平台
  • 网上智慧团建网站部署一个网站大概多少钱
  • 做的最成功的网站php可以做网站app吗
  • 西乡网站建设域名申请通过了网站怎么做
  • 如何添加网站图标制作网页方法
  • 宝安公司网站建设淘宝补流量平台
  • 电子商务企业网站有哪些定制家具价格
  • 西宁制作网站多少钱短视频seo营销
  • 湖南智能网站建设哪里好广西住房城乡建设厅网站
  • 绵阳网站关键词线上运营平台有哪些
  • 网站如何做百度才会收录做网站的一年能挣多少钱
  • 公司网站流程和费用四川网站建设外包
  • 德阳做网站热点新闻事件及评论2023
  • 宝山青岛网站建设wordpress恶意登录
  • 海南网站建设方面安庆网站建设哪家好
  • 上海网站排名松江新城建设有限公司网站
  • 建站网站模板下载个人网站的设计
  • 做网站页面的需要哪些技巧网站建设企业公司
  • 知乎网站建设用的工具专注南昌网站建设
  • 东莞专业的网站制作有哪些shopify如何做瀑布流网站
  • 长沙网站seo报价网站建设php怎么安装
  • wordpress企业站被黑动画制作软件排行榜
  • 舞蹈培训机构网站建设产品网络推广方案范文
  • 电子商务网站开发教程课后答案手机网站百度关键词排名
  • 在线网站建设收费新媒体运营方案
  • 我想在阿里巴巴上给别人做网站做便宜的宝贝的网站
  • 免费网站流量统计工具各地微信推广平台大全