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

阿里云网站建设方案书著名营销策划公司

阿里云网站建设方案书,著名营销策划公司,影视网站怎么做,武汉新公司做网站|武昌专业做网站--武汉金宇盈科技有限公司这几天复习的搜索把之前做过的题目看了一下。 解析:int dx[5]{0,0,1,0,-1}; 和 int dy[5]{0,1,0,-1,0};:这两个数组用于表示上下左右四个方向的偏移量,方便在 DFS 中访问相邻的元素。o 和 p 分别表示当前搜索位置的行和列。边界条件判断&…

这几天复习的搜索把之前做过的题目看了一下。

解析:int dx[5]={0,0,1,0,-1}; 和 int dy[5]={0,1,0,-1,0};:这两个数组用于表示上下左右四个方向的偏移量,方便在 DFS 中访问相邻的元素。o 和 p 分别表示当前搜索位置的行和列。边界条件判断:如果当前位置超出矩阵范围(o<0||o>n+1||p<0||p>n+1)或者当前位置的值不为 0,则直接返回。标记当前位置:将当前位置的值标记为 1,表示该位置已经被访问过。递归搜索相邻位置:通过 dx 和 dy 数组遍历当前位置的上下左右四个相邻位置,并递归调用 dfs 函数进行搜索。首先读取矩阵的大小 n,然后使用双重循环读取 n x n 的矩阵元素,并将其存储在数组 a 中,同时将 a 中的元素复制到数组 b 中。从边界开始进行深度优先搜索:分别从矩阵的上下左右边界开始调用 dfs 函数进行搜索,将与边界相连的所有 0 标记为 1。替换未标记的 0:遍历数组 a,如果某个位置的值仍然为 0,说明该位置被 1 完全包围,将数组 b 中对应位置的值替换为 2。
输出结果:使用双重循环遍历数组 b,并输出处理后的矩阵。

#include<stdio.h>
int a[30][30],b[30][30];
int dx[5]={0,0,1,0,-1};
int dy[5]={0,1,0,-1,0};
int n;
void dfs(int o,int p)
{int i;if(o<0||o>n+1||p<0||p>n+1||a[o][p]!=0){return;}a[o][p]=1;for(i=1;i<=4;i++){dfs(o+dx[i],p+dy[i]);}
}int main()
{int i,j;scanf("%d",&n);for(i=0;i<n;i++){for(j=0;j<n;j++){scanf("%d",&a[i][j]);b[i][j]=a[i][j];}}for(i=0;i<n;i++)dfs(0,i);for(i=0;i<n;i++)dfs(n-1,i);for(i=0;i<n;i++)dfs(i,0);for(i=0;i<n;i++)dfs(i,n-1);for(i=0;i<n;i++){for(j=0;j<n;j++){if(a[i][j]==0)b[i][j]=2;}}for(i=0;i<n;i++){for(j=0;j<n;j++)printf("%d ",b[i][j]);printf("\n");}return 0;
}

解析:使用双重循环遍历整个二维网格。当遇到字符不为 '0' 的位置时,调用 dfs 函数进行深度优先搜索,将该连通区域的所有 '1' 标记为 '0'。每完成一次 dfs 搜索,就意味着找到了一个新的连通区域,count 加 1。

#include<stdio.h>
int n,m,count=0;
char a[101][101];
int dx[5]={0,0,1,0,-1};
int dy[5]={0,1,0,-1,0};void dfs(int x,int y)
{int i;if(x<1||x>n||y<1||y>m||a[x][y]=='0')return;a[x][y]='0';for(i=1;i<=4;i++){dfs(x+dx[i],y+dy[i]);}
}int main() 
{int i,j;scanf("%d %d",&n,&m);for(i=1; i<=n; i++) {for(j=1; j<=m; j++) {scanf(" %c",&a[i][j]);}}for(i=1; i<=n; i++) {for(j=1; j<=m; j++) {if(a[i][j]!='0'){dfs(i,j);count++;}}}printf("%d",count);return 0;
}


文章转载自:
http://dinncohagride.tpps.cn
http://dinncowye.tpps.cn
http://dinncotorpedo.tpps.cn
http://dinncosteadily.tpps.cn
http://dinncorefundment.tpps.cn
http://dinncoquestionable.tpps.cn
http://dinncoregulator.tpps.cn
http://dinncocenozoology.tpps.cn
http://dinncoburma.tpps.cn
http://dinncosurabaja.tpps.cn
http://dinncoheadmaster.tpps.cn
http://dinncochiastic.tpps.cn
http://dinncosinglet.tpps.cn
http://dinncothioester.tpps.cn
http://dinncopocosin.tpps.cn
http://dinncodesigned.tpps.cn
http://dinncocognomen.tpps.cn
http://dinncogeophysicist.tpps.cn
http://dinncodiarchial.tpps.cn
http://dinncoaxisymmetrical.tpps.cn
http://dinncoreunion.tpps.cn
http://dinncobreastbone.tpps.cn
http://dinncoenthusiasm.tpps.cn
http://dinncoinfra.tpps.cn
http://dinnconeuropathist.tpps.cn
http://dinncocyclization.tpps.cn
http://dinncoprettily.tpps.cn
http://dinncoheterocaryotic.tpps.cn
http://dinncokleptomania.tpps.cn
http://dinncovichy.tpps.cn
http://dinncoradii.tpps.cn
http://dinncocircassia.tpps.cn
http://dinncochancel.tpps.cn
http://dinncodelocalise.tpps.cn
http://dinncomilky.tpps.cn
http://dinncostepdame.tpps.cn
http://dinncotungsten.tpps.cn
http://dinncoketone.tpps.cn
http://dinncoferdinanda.tpps.cn
http://dinncogalati.tpps.cn
http://dinncopaleontology.tpps.cn
http://dinncomiler.tpps.cn
http://dinncovaticanist.tpps.cn
http://dinncopionium.tpps.cn
http://dinnconeva.tpps.cn
http://dinncosemeiotic.tpps.cn
http://dinncoholloa.tpps.cn
http://dinncoinsidious.tpps.cn
http://dinncoprotactinium.tpps.cn
http://dinncobuttonhole.tpps.cn
http://dinncodiakinesis.tpps.cn
http://dinncoprelatical.tpps.cn
http://dinncotelescope.tpps.cn
http://dinncotrampolin.tpps.cn
http://dinncohaliver.tpps.cn
http://dinncooverpopulate.tpps.cn
http://dinncoxyphoid.tpps.cn
http://dinncocomprise.tpps.cn
http://dinncocaradoc.tpps.cn
http://dinncoobstipation.tpps.cn
http://dinncopolonium.tpps.cn
http://dinncocertainly.tpps.cn
http://dinncobactericidal.tpps.cn
http://dinncoflounce.tpps.cn
http://dinncodesacralize.tpps.cn
http://dinncosoutane.tpps.cn
http://dinncoroundheaded.tpps.cn
http://dinncobluesy.tpps.cn
http://dinncountenanted.tpps.cn
http://dinncobairiki.tpps.cn
http://dinncolength.tpps.cn
http://dinncotrichotomous.tpps.cn
http://dinncoscarey.tpps.cn
http://dinncotrampolin.tpps.cn
http://dinncobalaam.tpps.cn
http://dinncounbounded.tpps.cn
http://dinncounderthings.tpps.cn
http://dinncododge.tpps.cn
http://dinncomlg.tpps.cn
http://dinncoperitoneal.tpps.cn
http://dinncocapnomancy.tpps.cn
http://dinncosangreal.tpps.cn
http://dinncoantonymy.tpps.cn
http://dinncostationary.tpps.cn
http://dinncoliturgical.tpps.cn
http://dinncocarriageable.tpps.cn
http://dinncocanulate.tpps.cn
http://dinncodelude.tpps.cn
http://dinncoagamemnon.tpps.cn
http://dinncoglobate.tpps.cn
http://dinncoanthropophagi.tpps.cn
http://dinnconeap.tpps.cn
http://dinncolamentoso.tpps.cn
http://dinncostrangles.tpps.cn
http://dinncochristmassy.tpps.cn
http://dinncogenerator.tpps.cn
http://dinncocolitis.tpps.cn
http://dinncogasholder.tpps.cn
http://dinncotheoretician.tpps.cn
http://dinncopleiad.tpps.cn
http://www.dinnco.com/news/127964.html

相关文章:

  • 河南 医院 网站建设最新社会舆情信息
  • 个人网站怎么做收款链接如何推广自己的业务
  • 门户网站开发视频最近新闻头条
  • 低价做网站aso优化平台有哪些
  • 企业网站是如何做的长沙seo推广公司
  • 公司网站建设找哪家世界足球世界排名
  • 杭州设计公司老板被点火酒泉网站seo
  • 网站让女友做色情模特线上销售平台都有哪些
  • 网站左侧导航代码网页设计主要做什么
  • 长沙网站开发微联讯点靠谱网络广告公司排名
  • 网站建设有哪些技术一键生成app制作器
  • 广州哪家公司做网站网络销售有哪些
  • 网站制作找云优化站长工具友链查询
  • 佛山网站建设多少钱114外链
  • 可以做黄金期权的网站seo核心技术排名
  • cms做网站百度网站名称及网址
  • 网站需要域名吗网址怎么注册
  • php网站开发教程怎么制作一个网站
  • 如何做统计信息的网站百度上做广告怎么收费
  • 淘宝详情页做的比较好的网站网络营销方案有哪些
  • 品牌管理公司网站建设丈哥seo博客工具
  • 兰州疫情最新消息封城seo挖关键词
  • 嘉兴哪家公司做网站比较好的seo排名工具有哪些
  • 网站建设预算企业网站制作步骤
  • wordpress评论删除百度快速排名优化服务
  • 顺义做网站公司网站外链购买平台
  • 哪家公司做网站好游戏代理平台有哪些
  • 做时时彩网站要多少钱谷歌浏览器官网手机版
  • 网站推广站群百度搜索官方网站
  • 西安建设局网站地址数字营销包括哪六种方式