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

成都私人定制旅游公司排名深度优化

成都私人定制旅游公司排名,深度优化,求职简历模板2021,旺道seo网站优化大师from#xff1a; https://leetcode.cn/studyplan/top-100-liked/ bfs 具有 边权为1 的最短路性质 拓扑排序#xff0c;入度 Trie树#xff0c; 高效存储 字符串【见鬼#xff0c;不知道为什么写错#xff0c;需要掌握熟练度】 文章目录 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(vectorvectorchar 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,vectorvectorchar 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 pairint,int PII;int dx[4] {-1,0,1,0}, dy[4] {0,1,0,-1};int numIslands(vectorvectorchar grid) {if(grid.empty() || grid[0].empty()) return 0;n grid.size(), m grid[0].size();int res 0;for(int i 0;in;i)for(int j0;jm;j)if(grid[i][j] 1){res ;bfs(i,j,grid);}return res;}void bfs(int x,int y,vectorvectorchar grid){queuePII q;q.push({x,y});grid[x][y] 0;while(!q.empty()){auto t q.front();q.pop();for(int i0;i4;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(vectorvectorint grid) {int n grid.size(), m grid[0].size();bool st[n][m];memset(st, 0, sizeof st);queuepairint,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, vectorvectorint prerequisites) {// 拓扑排序int d[numCourses];memset(d, 0, sizeof d);vectorint g[numCourses];for(auto c : prerequisites) {int a c[0], b c[1];g[a].push_back(b);d[b] ;}queueint 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 i0;i26;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.hkea.cn/news/14449948/

相关文章:

  • 重庆哪里可以做网站的为网站设计手机版
  • 襄樊北京网站建设关于网站建设外文文献
  • 做教案找资料有哪些网站dz网站建设教程
  • 网站开发语言版本不同鞍山新款网站制作哪家好
  • 网站不兼容360浏览器服装设计最好的出路
  • ui设计师面试seo最新快速排名
  • 专业做网站公司怎么样网页设计师证书什么时候考
  • wordpress主题 反盗版百度怎么做关键词优化
  • 企业网站建设多长时间哪些网站教你做美食的
  • 无锡城乡建设部网站首页网站登录页面怎么做的
  • 网站布局设计网站地图创建
  • 门户网站 cms家具公司网站源码
  • 资料库网站应该怎么做wordpress得到分类id
  • 免费源码下载网站frontpage网页制作实例
  • 网站空间的地址全国建设工程四库一平台
  • wordpress网站在线安装桐梓县工程建设交易网站
  • 电子商务网站建设参考文献山西百度查关键词排名
  • qq网站登录入口长沙网络营销 公司
  • 怎么建网站教程深圳人才招聘网
  • 番禺制作网站系统wordpress 时区 8小时
  • 科技与狠活是什么梗太原网站优化教程
  • 南开区网站建设公司淘宝指数查询官网
  • 浙江省一建建设集团网站建站之星网站登录
  • 怎么免费建立个人网站wordpress 图片加水印
  • 建设网站好公司哪家好WordPress站点地址填错
  • 免费的网站域名查询建设单位到江川区住房和城乡建设局网站
  • 杭州网站基建wordpress网关支付
  • 专业网站建设的公司网络推广引流是什么意思
  • 学生免费建设网站建设网站企业网上银行登录入口官方
  • 网站404设置昆明做网站词排名优化