Time limit for Image utility area: theMs | Memory Limit:65535KB Difficulty:4
-
-
Descriptive narrative
-
"ACKing" classmate once made an image processing project when. Encounter a problem, he needs to pick out a picture of a black line comfortably into the area within the image, now ask you to help him finish the first step. Turn the black line comfortably outside the area to black.
Fig. 1 Fig. 2
It is known that there is no cross (2) around the black line, and. In addition to the dots on the black line, there is no pure black in the image (that is, the pixel is 0 points).
-
-
Input
-
-
First row input group number of test data N (0<n<=6)
The first line of the test data for each group is two integers w,h the width and height of the picture (3<=w<=1440,3<=h<=960)
The next H line. Each row has a W positive integer that represents the pixel value of the point.
(The pixel values are between 0 and 255.) 0 indicates black. 255 = white)
-
-
Output
-
-
outputs the pixel value of each point in the image after the black box is blackened in matrix form.
-
-
Example input
-
-
15 5100 253 214 146 120123 0 0 0 054 0 33 47 0255 0 0 78 014 11 0 0 0
-
-
Example output
-
-
0 0 0 0 00 0 0 0 00 0 33 47 00 0 0 78 00 0 0 0 0
Analysis: Add a lap 1 to the original figure.
Code:
#include <stdio.h> #include <string.h> #include <queue> #define W 1445#define H 965using 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); Here's X. Y. Must be less than or equal to 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.F Ront (); 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]), and for (j = 2; j<= W; j + +) printf ("% D ", Map[i][j]);p rintf (" \ n ");} printf ("\ n");} return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
NYOJ 92 's Photos saleable area "BFS"