NYOJ 92 图像有用区域
2014-07-19 10:24
260 查看
[b]图像有用区域[/b]
时间限制:3000ms|内存限制:65535KB难度:4
[b]描述[/b]
“ACKing”同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取出图片中某个黑色线圏成的区域以内的图片,现在请你来帮助他完成第一步,把黑色线圏外的区域全部变为黑色。
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<vector> #include<climits> #include<algorithm> #include<cmath> #include<queue> #defineLLlonglong usingnamespacestd; introws,cols,mp[1000][1500]; queue<int>q; voidbfs(intx,inty){ constintdir[4][2]={0,-1,0,1,-1,0,1,0}; inti,j,tx,ty,u,v; q.push(x); q.push(y); while(!q.empty()){ tx=q.front(); q.pop(); ty=q.front(); q.pop(); for(i=0;i<4;i++){ u=tx+dir[i][0]; v=ty+dir[i][1]; if(!mp[u][v])continue; if(u<0||v<0||u>=999||v>=1499)continue; mp[u][v]=0; q.push(u); q.push(v); } } } intmain(){ intks,i,j; scanf("%d",&ks); while(ks--){ scanf("%d%d",&cols,&rows); for(i=0;i<1000;i++) for(j=0;j<1500;j++) mp[i][j]=1; for(i=1;i<=rows;i++){ for(j=1;j<=cols;j++) scanf("%d",mp[i]+j); } while(!q.empty())q.pop(); bfs(0,0); for(i=1;i<=rows;i++){ for(j=1;j<=cols-1;j++) printf("%d",mp[i][j]); printf("%d\n",mp[i][j]); } } return0; }
ViewCode
为什么要加圈1呢?嘻嘻。。。。。因为从左上角开始搜,如果全是0啊,而右边可能不是啊。。那么就会出现搜不下去的情况,导致WA。。。。。加圈是为了保0圈外面是连续的一片
相关文章推荐
- nyoj--92--图像有用区域(模拟)
- NYOJ 92 图像有用区域 【bfs】
- NYOJ 92 图像有用区域
- nyoj 92 图像有用区域
- nyoj 92 图像有用区域 【BFS】 【好题 】
- NYOJ92-图像的有用区域
- nyoj 92 图像有用区域(dfs)
- nyoj 92 图像有用区域
- NYoj 92 图像有用区域
- nyoj-92-图像有用区域
- nyoj92图像有用区域——BFS
- 【NYOJ-92- 图像有用区域-BFS】
- NYOJ 92 图像有用区域
- NYOJ92图像有用区域
- 图像有用区域nyoj92
- nyoj 92 图像有用区域
- NYOJ-92 图像有用区域
- NYOJ-92 图像有用区域(bfs)
- NYOJ 92 图像有用区域(广搜)
- NYOJ92图像有用区域