Home > Back-end >  Ask bosses
Ask bosses

Time:09-15

18: tumor size
See submit statistical questions
The total time limit: 1000 ms memory limit: 65536 KB
Description
On a square of gray level images, the tumor is a rectangular area, the edge of the tumor's pixels in images with 0, said other tumor within and outside of the point are expressed in 255, now you are asked to write a program to calculate the number of pixels within the tumor (not including point) on the edge of the tumor, tumor known parallel to the edge of the image edge,

Enter
There is only one test sample, the first line is an integer n, said the square side length of the image, followed by n lines each have n integers, value of 0 or 255, integers separated with a space between, n is not more than 1000 known,
O
Output one line, which contains an integer, for the requirements of the tumour by the number of pixels,
The sample input
5
255 255 255 255 255
255 0 0 0, 255
255 0 255 0 255
255 0 0 0, 255
255 255 255 255 255
Sample output
1
Which is wrong, ask bosses outcome was all right but
#include
using namespace std;
Int a [1005] [1005].
Int main ()
{
Int n, b, s, k, f, e, t, c, d;
Cin> n;
for(int i=1; i<=n; I++)
{
For (int j=1; j<=n; J++)
{
Cin> A, [I] [j].
}
}
K=1;
for(int i=1; i<=n; I++)
{
If (a [I] [k]==0)
{
E=I;
F=k;
break;
}
k++;
}
T=n;
For (int j=n; J>=0; J -)
{
If (a [t] [j]==0)
{
C=j;
D=t;
break;
}
T -;
}
S=(c - e - 1) * (d - f - 1);
Cout<& lt; s;
return 0;
}

CodePudding user response:

From the first lookup cycle, as long as meet 0 has no longer continue to find, this is what you think is right?

CodePudding user response:

What do you want to find out the bottom right hand corner of the upper left corner way to calculate the area of the rectangle
The basic train of thought can
But there is an error
Find ways to the upper left corner and the lower right corner you are in diagonal tumors but can not find diagonal!
For example,

Another look from the topic
I'm not so sure edge is not fixed is 1 pixel
Will there be the width of the 2
the condition of theCoordinates, it is best to find the coordinates of tumor directly find
Don't work on the fringe

CodePudding user response:

If find the edge, you can:
 
#include

Int main ()
{
Int j [1000], n, I, j, x=0, y=0;

For (the scanf (" % d ", & amp; N), I=0; i {
For (j=0; J & lt; n; J++) the scanf (" % d ", & amp; M [j]);
For (j=0; J & lt; N;)
if (! M [j++])
{
Y++;
if (! M [j] & amp; & ! X) while (j & lt; N & amp; & ! M x++ [j++]);
break;
}
}
Printf (" % d \ n ", (x - 1) * (y - 2));

return 0;
}

  • Related