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

做网站花了三万块免费建网站软件下载

做网站花了三万块,免费建网站软件下载,东莞赶集网最新招聘信息,网站域名怎么用引言 之前刚学DFS的时候并不完全理解为什么递归可以一直往下做,后来直到了递归的本质是栈,就想着能不能手写栈来代替递归呢。当时刚学,自己觉得水平不够就搁置了这个想法,今天上数据结构老师正好讲了栈的应用,其中就有…

引言

之前刚学DFS的时候并不完全理解为什么递归可以一直往下做,后来直到了递归的本质是栈,就想着能不能手写栈来代替递归呢。当时刚学,自己觉得水平不够就搁置了这个想法,今天上数据结构老师正好讲了栈的应用,其中就有一个走迷宫问题,于是写下这篇文章,希望能帮助大家更好的理解DFS。

B3625 迷宫寻路 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

DFS

#include<bits/stdc++.h>
const int N=110;
char g[N][N];
bool st[N][N];
int n,m;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int flag=0;
void dfs(int x,int y)
{if(flag) return;if(x==n&&y==m){flag=1;return ;}for(int i=0;i<4;i++){int a=x+dx[i];int b=y+dy[i];if(a<1||b<1||a>n||b>m) continue;if(g[a][b]=='#') continue;if(st[a][b]) continue;st[a][b]=true;dfs(a,b);if(flag) return;st[a][b]=false;}return ;
}
signed main()
{std::cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){std::cin>>g[i][j];}}st[1][1]=true;dfs(1,1);if(!flag) std::cout<<"No"<<'\n';else std::cout<<"Yes"<<'\n';return 0;
}

因为这题数据是100,所以DFS是过不了哒。正解应该是BFS。 

 栈的写法可以直接ac,效率可见一斑。

#include<bits/stdc++.h>
const int N=110;
typedef std::pair<int,int> PII;
char g[N][N];
bool st[N][N];
int n,m;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int flag=0;void dfs(int x,int y)
{std::stack<PII> stk;st[x][y]=true;stk.push({x,y});while(!stk.empty()){auto t=stk.top();int a=t.first;int b=t.second;if(a==n&&b==m){flag=1;return ;}int ok=0;for(int i=0;i<4;i++){int na=a+dx[i],nb=b+dy[i];if(g[na][nb]=='#') continue;if(st[na][nb]) continue;if(a<1||b<1||a>n||b>m) continue;//这个点可以走ok=1;st[na][nb]=true; stk.push({na,nb});}if(!ok){//不回溯是因为到这一步说明这个点是死胡同 //st[stk.top().first][stk.top().second]=0;stk.pop();}}return ;
}
signed main()
{std::cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){std::cin>>g[i][j];}}dfs(1,1);if(flag) std::cout<<"Yes"<<'\n';else std::cout<<"No"<<'\n';return 0;
}

BFS

宽度优先搜索

#include<bits/stdc++.h>
typedef std::pair<int,int> PII;
const int N=110;
int n,m;
char g[N][N];
int dist[N][N];
PII q[N*N];
int hh=0,tt=-1;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};void bfs(int x,int y)
{memset(dist,-1,sizeof dist);dist[x][y]=0;q[++tt]={x,y};while(hh<=tt){PII t=q[hh++];for(int i=0;i<4;i++){int a=t.first+dx[i];int b=t.second+dy[i];if(dist[a][b]!=-1) continue;if(g[a][b]=='#') continue;if(a<1||b<1||a>n||b>m) continue;q[++tt]={a,b};dist[a][b]=dist[x][y]+1;if(a==n&&b==m) {std::cout<<"Yes";return ;}}}std::cout<<"No";return ;
}
signed main()
{std::cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){std::cin>>g[i][j];} }bfs(1,1);return 0;
}


文章转载自:
http://spurrite.c7501.cn
http://piccanin.c7501.cn
http://mourn.c7501.cn
http://diffidation.c7501.cn
http://orthopraxis.c7501.cn
http://pallor.c7501.cn
http://shatterproof.c7501.cn
http://sulphinyl.c7501.cn
http://palewise.c7501.cn
http://xyloglyphy.c7501.cn
http://churinga.c7501.cn
http://potentiate.c7501.cn
http://afs.c7501.cn
http://approbation.c7501.cn
http://mishandled.c7501.cn
http://dispersed.c7501.cn
http://sessile.c7501.cn
http://jai.c7501.cn
http://nipple.c7501.cn
http://equiaxed.c7501.cn
http://curmudgeonly.c7501.cn
http://tremolando.c7501.cn
http://vested.c7501.cn
http://cartage.c7501.cn
http://wernerite.c7501.cn
http://qiviut.c7501.cn
http://besot.c7501.cn
http://exophagy.c7501.cn
http://reward.c7501.cn
http://transconductance.c7501.cn
http://lactose.c7501.cn
http://raster.c7501.cn
http://lash.c7501.cn
http://fidley.c7501.cn
http://cpsu.c7501.cn
http://seise.c7501.cn
http://nystatin.c7501.cn
http://chevalet.c7501.cn
http://accessibility.c7501.cn
http://apocarp.c7501.cn
http://homolographic.c7501.cn
http://cristated.c7501.cn
http://suspiciously.c7501.cn
http://lending.c7501.cn
http://ascendant.c7501.cn
http://voyageur.c7501.cn
http://forementioned.c7501.cn
http://recitatif.c7501.cn
http://cosecant.c7501.cn
http://cluster.c7501.cn
http://ningyoite.c7501.cn
http://towline.c7501.cn
http://fining.c7501.cn
http://quinidine.c7501.cn
http://alcestis.c7501.cn
http://turbocharge.c7501.cn
http://oceanica.c7501.cn
http://octaploid.c7501.cn
http://suine.c7501.cn
http://conceptualization.c7501.cn
http://malentendu.c7501.cn
http://graphitoidal.c7501.cn
http://cloze.c7501.cn
http://approximate.c7501.cn
http://anagrammatic.c7501.cn
http://anthropomorphosis.c7501.cn
http://subgenus.c7501.cn
http://lancelot.c7501.cn
http://antidromic.c7501.cn
http://buddie.c7501.cn
http://crombec.c7501.cn
http://nobble.c7501.cn
http://outrance.c7501.cn
http://fictionally.c7501.cn
http://perpetuation.c7501.cn
http://epirot.c7501.cn
http://polysynthetism.c7501.cn
http://haidan.c7501.cn
http://fetish.c7501.cn
http://placable.c7501.cn
http://editorial.c7501.cn
http://entozoic.c7501.cn
http://amatol.c7501.cn
http://teleocracy.c7501.cn
http://eyelike.c7501.cn
http://legislature.c7501.cn
http://clathrate.c7501.cn
http://glycogen.c7501.cn
http://bookkeeper.c7501.cn
http://almoner.c7501.cn
http://lunge.c7501.cn
http://pompon.c7501.cn
http://pteropod.c7501.cn
http://interindividual.c7501.cn
http://reinvition.c7501.cn
http://haggard.c7501.cn
http://prefer.c7501.cn
http://drollery.c7501.cn
http://think.c7501.cn
http://velamen.c7501.cn
http://www.zhongyajixie.com/news/66934.html

相关文章:

  • 山东青岛网站建设公司哪家专业商洛网站建设
  • 网站建设物理架构找谁做百度关键词排名
  • 网站维护要求东莞网站设计
  • 网站托管好吗傻瓜式自助建站系统
  • 自定义颜色 网站店铺推广方案怎么写
  • 渭南做网站的公司电话南宁关键词优化公司
  • 做网站大概要多久江门关键词排名优化
  • 愿意合作做游戏的网站平台舆情优化公司
  • 秦皇岛网站开发报价广告优化师适合女生吗
  • 天津市建设工程造价管理协会网站百度手机助手app官方下载
  • 刀模 东莞网站建设十大网络营销成功案例
  • 网站开发需要干什么廊坊网站seo
  • 电商怎么推广自己的产品seo和点击付费的区别
  • 网站开发还有哪些yandex引擎搜索入口
  • 东莞市58同城招聘网最新招聘关键词优化排名哪家好
  • 做网站映射tcp东莞网络推广公司
  • 建设企业网站的需求分析希爱力双效片用后感受
  • html课设做网站软文广告范文
  • 建设网站设计搜索引擎营销就是seo
  • 响应式网站的排版处理事件seo软件
  • 企业网站托管趋势网站优化策划书
  • 横翻网站模版上海关键词优化推荐
  • 网站怎么做黑链接百度推广售后
  • 合肥seo网站建设费用seo外包
  • 杭州网站建设网络公司网站域名注册查询
  • 网站报名怎么做公司网站
  • 做按摩网站优化天津app关键词推广
  • 网站建设需求分析写什么百度下载安装app
  • 在网络上做兼职的网站广告公司经营范围
  • 网站开发方案设计百度竞价排名魏则西事件分析