图像有用区域nyoj92
来源:互联网 发布:马来西亚知乎 编辑:程序博客网 时间:2024/05/16 10:39
这题其实不难,就是一个bfs;
#include<stdio.h>#include<stdlib.h>#include<queue>using namespace std;int map[965][1445];int dir[4][2]={1,0, 0,1, -1,0, 0,-1};typedef struct Point{int x,y;}P;queue<P> Q;int w,h;int main(){//freopen("d:\\data\\1.txt","r",stdin);void bfs();int ncase;int i,j;P tt;scanf("%d",&ncase);while(ncase--){scanf("%d%d",&w,&h);for(i=0;i<h;i++){for(j=0;j<w;j++){scanf("%d",&map[i][j]);if((i==0 || j==0 || i==(h-1) || j==(w-1) )&& map[i][j]!=0){tt.x=j;tt.y=i;map[i][j]=0;Q.push(tt);}}}bfs();for(i=0;i<h;i++){for(j=0;j<w;j++)printf("%d ",map[i][j]);printf("\n");}}return 0;}void bfs(){P cur,next;while(!Q.empty()){int k;cur=Q.front();Q.pop();for(k=0;k<4;k++){next.x=cur.x+dir[k][0];next.y=cur.y+dir[k][1];if(next.x>=0 && next.x<w && next.y>=0 && next.y<h && map[next.y][next.x]!=0){map[next.y][next.x]=0;Q.push(next);}}}while(!Q.empty())Q.pop();return ;}
上面的代码不不需要讲了吧,只要你会bfs你就会做,但是注意这题有个坑,就是他说的长度和高度,我之前提交几次,就是被这个坑了,其实自习看看还是怪自己粗心大意,
好好看题,养成好习惯,对以后的额工作生活都有好处。
0 0
- NYOJ92-图像有用区域
- 图像有用区域nyoj92
- NYOJ92图像有用区域
- NYOJ92图像有用区域
- nyoj92 图像有用区域
- NYOJ92-图像的有用区域
- NYOJ92 图像有用区域 【BFS】
- nyoj92图像有用区域【bfs】
- NYOJ92 图像有用区域(广搜BFS)
- NYOJ92~图像有效区域
- nyoj92 图像有用区间(dfs)
- 图像有用区域
- NYOJ 图像有用区域
- 图像有用区域
- 图像有用区域
- 图像有用区域
- acm_92图像有用区域
- 图像有用区域 bfs
- NYOJ 952 最大四边形
- spring No mapping found for HTTP request with URI
- nyist--摆格子
- Android自动化测试之Robotium导包
- 整数的分划问题(Java)实现
- 图像有用区域nyoj92
- UVA12304-2D Geometry 110 in 1!
- libevent源码深度剖析一
- STM32 Systick定时器
- Android开发之各种双向侧滑菜单的实现
- Android Api 检查参数状态Api
- mac下安装wget
- iptables:unrecognized service 的解决方法
- 安卓真机调试报错:Application already deployed. No need to reinstall.