nyoj 92 图片实用面积【bfs】
图像实用区域
- 描写叙述
-
“ACKing”同学曾经做一个图像处理的项目时。遇到了一个问题,他须要摘取出图片中某个黑色线圏成的区域以内的图片,如今请你来帮助他完毕第一步。把黑色线圏外的区域所有变为黑色。

图1 图2
已知黑线各处不会出现交叉(如图2),而且。除了黑线上的点外,图像中没有纯黑色(即像素为0的点)。
- 输入
- 第一行输入測试数据的组数N(0<N<=6)
每组測试数据的第一行是两个个整数W,H分表表示图片的宽度和高度(3<=W<=1440,3<=H<=960)
随后的H行。每行有W个正整数,表示该点的像素值。(像素值都在0到255之间。0表示黑色。255表示白色)
- 输出
- 以矩阵形式输出把黑色框之外的区域变黑之后的图像中各点的像素值。
- 例子输入
-
1
5 5
100 253 214 146 120
123 0 0 0 0
54 0 33 47 0
255 0 0 78 0
14 11 0 0 0 - 例子输出
-
0 0 0 0 0
0 0 0 0 0
0 0 33 47 0
0 0 0 78 0
0 0 0 0 0
分析:在原来的图上加一圈1.
代码:
#include <stdio.h>
#include <string.h>
#include <queue>
#define W 1445
#define H 965
using namespace std;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0}; int map[H][W], w, h;
struct node{
int x, y;
}; int limit(int x, int y){
return (x>=0&&x<=h+1&&y>=0&&y<=w+1); //这里的x。y。一定小于等于w+1,h+1;
} void bfs(){
int i;
node st;
st.x = st.y = 0;
queue<node > q;
q.push(st);
while(!q.empty()){
node temp = q.front();
for(i = 0; i < 4; i ++){
node cur = temp;
cur.x+=dx[i]; cur.y+=dy[i];
if(map[cur.x][cur.y] == 0) continue;
if(!limit(cur.x, cur.y)) continue;
//if(cur.x < 0||cur.y <0||cur.x > h+1||cur.y > w+1 || map[cur.x][cur.y] == 0) continue;
map[cur.x][cur.y] = 0;
q.push(cur);
}
q.pop();
}
} int main(){
int t, i, j;
scanf("%d", &t);
while(t --){
scanf("%d%d", &w, &h);
for(i = 0; i <= w+1; i ++){
map[0][i] = 1;
map[h+1][i] = 1;
}
for(i = 0; i <= h+1; i++){
map[i][0] = 1;
map[i][w+1] = 1;
}
for(i = 1; i <= h; i ++)
for(j = 1; j <= w; j++)
scanf("%d", &map[i][j]);
bfs();
for(i = 1; i <= h; i++){
printf("%d", map[i][1]);
for(j = 2; j<= w; j++)
printf(" %d", map[i][j]);
printf("\n");
}
printf("\n");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
nyoj 92 图片实用面积【bfs】的更多相关文章
- nyoj 92 图像有用区域
点击打开链接 图像有用区域 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取 ...
- nyoj 483 Nightmare【bfs+优先队列】
Nightmare 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Ignatius had a nightmare last night. He found him ...
- NYOJ 284 坦克大战 bfs + 优先队列
这类带权的边的图,直接广搜不行,要加上优先队列,这样得到的结果才是最优的,这样每次先找权值最小的,代码如下 #include <stdio.h> #include <iostream ...
- nyoj三个水杯(bfs)
三个水杯 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个为空杯子.三个水杯之间相互 ...
- NYOJ 92
1.深搜(会爆栈,通过开全局栈模拟递归) 爆栈代码 # include<iostream> # include<string> # include<string.h> ...
- nyoj 27-水池数目(BFS, DFS)
27-水池数目 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:17 submit:22 题目描述: 南阳理工学院校园里有一些小河和一些湖泊,现在,我 ...
- nyoj 21-三个水杯(BFS)
21-三个水杯 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:7 submit:18 题目描述: 给出三个水杯,大小不一,并且只有最大的水杯的水是装 ...
- nyoj 58-最少步数 (BFS)
58-最少步数 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:17 submit:22 题目描述: 这有一个迷宫,有0~8行和0~8列: 1,1,1 ...
- C++ 网络爬虫实现
最近有个概念吵得很火,网络爬虫,但是基本都是用什么python或者JAVA写,貌似很少看到用c++写的,我在网上找了一个,看到其实还是很简单的算法 算法讲解:1.遍历资源网站 2.获取html信息 ...
随机推荐
- 在vue中使用font-awesome
1.安装 cnpm i font-awesome -S 2.在main.js中引入 import 'font-awesome/css/font-awesome.min.css'
- excel-vlookup (跨文件引用)
- 【53.57%】【codeforces 722D】Generating Sets
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Android 自定义RadioButton样式
上面这种3选1的效果如何做呢?用代码写? 其实有更简单的办法,忘了RadioButton有什么特性了吗? 我就用RadioButton实现了如上效果,其实很简单的. 首先定义一张background ...
- [Node.js] Test Node RESTful API with Mocha and Chai
In this lesson, we will use Chai's request method to test our Node application's API responses.By th ...
- Android 监听软键盘按键的三种方式
前言: 我们在Android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“Go”按键加载url页面:在点击搜索框的时候,点击右下角的searc ...
- protobuf入门教程
1.简介和安装 2.消息类型 3.proto3 与 proto2 的区别 4.常用序列化/反序列化接口 5.repeated限定修饰符 6.枚举(enum).包(package) 7.导入定义(imp ...
- html5-3 html5标签(热点地图如何实现)(边学边做)
html5-3 html5标签(热点地图如何实现)(边学边做) 一.总结 一句话总结:热点地图用绝对定位实现. 1.自定义列表怎么弄? dl 自定义列表dt 自定义标题dd 自定义列表内容 2. ...
- Ajax基础与Json应用(二)
九.jQuery 实现Ajax应用 1.使用load()方法异步请求数据 使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为: load(url, ...
- android生成分享长图而且加入全图水印
尊重他人的劳动成果.转载请标明出处:http://blog.csdn.net/gengqiquan/article/details/65938021. 本文出自:[gengqiquan的博客] 领导近 ...