图像有用区域
来源:互联网 发布:钱咖试客类似的软件 编辑:程序博客网 时间:2024/05/17 03:07
图像有用区域
时间限制:3000 ms | 内存限制:65535 KB
难度:4
- 描述
“ACKing”同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取出图片中某个黑色线圏成的区域以内的图片,现在请你来帮助他完成第一步,把黑色线圏外的区域全部变为黑色。
图1 图2
已知黑线各处不会出现交叉(如图2),并且,除了黑线上的点外,图像中没有纯黑色(即像素为0的点)。
- 输入
- 第一行输入测试数据的组数N(0<N<=6)
每组测试数据的第一行是两个个整数W,H分表表示图片的宽度和高度(3<=W<=1440,3<=H<=960)
随后的H行,每行有W个正整数,表示该点的像素值。(像素值都在0到255之间,0表示黑色,255表示白色) - 输出
- 以矩阵形式输出把黑色框之外的区域变黑之后的图像中各点的像素值。
- 样例输入
15 5100 253 214 146 120123 0 0 0 054 0 33 47 0255 0 0 78 014 11 0 0 0
- 样例输出
0 0 0 0 00 0 0 0 00 0 33 47 00 0 0 78 00 0 0 0 0
- 来源
- [张云聪]原创
- 上传者
张云聪
#include<stdio.h> #include<queue>using namespace std;int map[995][1442];int step[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};struct Node{int x;int y;};void BFS(int a, int b, int h, int w){queue<struct 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+step[i][0];t2.y = t1.y+step[i][1];if(t2.x<0||t2.y<0||t2.x>h+1||t2.y>w+1||map[t2.x][t2.y]==0)continue;map[t2.x][t2.y] = 0;q.push(t2);}}}int main(){int t,i,j;int w, h;scanf("%d",&t);while(t--){scanf("%d%d",&h,&w);//for(i=0;i<h;i++)//{//map[i][0] = 1;//map[i][w+1] = 1;//}////for(i=0;i<w;i++)//{//map[0][i] = 1;//map[h+1][i] = 1;//}for(i=1;i<=h;i++) for(j=1;j<=w;j++) scanf("%d",&map[i][j]); BFS(1,1,h,w); for(i=1;i<=h;i++){ for(j=1;j<=w;j++) printf("%d",map[i][j]); printf("\n"); }}}
参考:http://blog.csdn.net/ych1035235541/article/details/9204717
0 0
- 图像有用区域
- NYOJ92-图像有用区域
- NYOJ 图像有用区域
- 图像有用区域
- 图像有用区域
- 图像有用区域
- 图像有用区域nyoj92
- acm_92图像有用区域
- 图像有用区域 bfs
- 图像有用区域
- nyoj--图像有用区域
- 图像有用区域
- 图像有用区域
- NYOJ92图像有用区域
- 图像有用区域
- 图像有用区域1
- 图像有用区域 【BFS】
- 图像有用区域
- 一个故事
- 解决Android的Activity启动后页面没有绘制黑屏问题
- Java工程师成神之路
- 通过一个例子快速上手矩阵求导
- java堆压测
- 图像有用区域
- JAVA gc垃圾回收机制
- YTU:C语言习题 矩形法求定积分
- MyReport实践:为ERP系统添加打印功能
- [LeetCode] Validate Binary Search Tree
- 移动硬盘打不开,提示“文件或目录损坏无法读取”
- leetCode题解
- Windows 10 配置vagrant环境
- 设计模式--创建型(2)