nyoj92 图像有用区间(dfs)
来源:互联网 发布:简单工程造价软件 编辑:程序博客网 时间:2024/06/04 18:50
//广搜#include<stdio.h>#include<string.h>#include<queue>using namespace std;struct node{int x;int y;};int w,h;int mat[961][1441];int xx[4]={0,0,-1,1};int yy[4]={1,-1,0,0};void bfs(int a,int b){queue<node>q;node t1,t2;t1.x =a;t1.y =b;q.push(t1);while(!q.empty()){t1=q.front();q.pop();for(int i=0;i<4;i++){t2.x =t1.x +xx[i];t2.y =t1.y +yy[i];if(t2.x <0||t2.y<0||t2.x>h+1||t2.y>w+1||mat[t2.x][t2.y]==0)continue;mat[t2.x][t2.y]=0;q.push(t2);}}}int main(){int n;scanf("%d",&n);while(n--){int a;scanf("%d%d",&w,&h);memset(mat,1,sizeof(mat));for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){scanf("%d",&a);mat[i][j]=a;}bfs(0,0);for(int i=1;i<=h;i++){for(int j=1;j<=w;j++){if(j==w)printf("%d\n",mat[i][j]);else printf("%d ",mat[i][j]);}}}return 0;}
//深搜# include<stdio.h># include<string.h>int a[1000][1445],w,h;void dfs(int c1,int c2){if(a[c1][c2]&&c1>=0&&c2>=0&&c1<=h+1&&c2<=w+1){a[c1][c2]=0;dfs(c1,c2+1);dfs(c1+1,c2);dfs(c1-1,c2);dfs(c1,c2-1);}}int main(){int t;scanf("%d",&t);while(t--){ memset(a,1,sizeof(a));//在数组外在 int i,j;scanf("%d%d",&w,&h);for(i=1;i<=h;i++)for(j=1;j<=w;j++)scanf("%d",&a[i][j]);dfs(0,0);for(i=1;i<=h;i++){for(j=1;j<=w;j++)printf("%d ",a[i][j]);printf("\n");}}return 0;}
阅读全文
0 0
- nyoj92 图像有用区间(dfs)
- NYOJ92-图像有用区域
- 图像有用区域nyoj92
- NYOJ92图像有用区域
- NYOJ92图像有用区域
- nyoj92 图像有用区域
- NYOJ92-图像的有用区域
- NYOJ92 图像有用区域 【BFS】
- nyoj92图像有用区域【bfs】
- NYOJ92 图像有用区域(广搜BFS)
- nyoj 92 图像有用区域(dfs)
- NYOJ92~图像有效区域
- 92 图像有用区域【bfs+dfs(re)】
- NYOJ92汉诺塔(三)
- 黑白图像(DFS)
- 图像有用区域(bfs)
- 图像有用区域(bfs)
- HDU-5696-区间的价值(DFS)
- rocketMq
- Thinkphp PHPExcel批量导入数据到数据库
- 手风琴菜单,且隐藏滚动条保留滚动功能
- 文档的发布
- 【Android应用开发学习】—Toast使用方法大全
- nyoj92 图像有用区间(dfs)
- Centos 7 matplotlib 远程绘图
- java的几种对象(po,dto,dao等)
- 二叉搜索树转为双向链表
- 欢迎使用CSDN-markdown编辑器
- 学习JAVA
- 云计算开发者必会的企业级互联网分布式系统应用架构学习
- zookeeper集群搭建
- 欢迎使用CSDN-markdown编辑器