1091. Acute Stroke (30)
One important factor to identify acute stroke (acute stroke) is the volume core. Given the results of image analysis into which the core regions are identified in each MRI slice, your job are to calculate t He volume the stroke core.
Input Specification:
Each input file contains one test case. For each case, the contains 4 positive integers:m, N, L and T, where M and N are the sizes of each slice (i.e. Pixels of a slice are in a M by N matrix, and the maximum resolution be 1286 by 128); L (<=60) is the number of slices of a brain; And T is the integer threshold (i.e. if the volume of a connected core are less than T, then that core must isn't be counted) .
Then L slices are given. Each slice was represented by an M by N matrix of 0 ' s and 1 ' s, where 1 represents a pixel of stroke, and 0 means normal. Since the thickness of a slice is a constant and we only have to count the number of 1 's to obtain the volume. However, there might is several separated core regions in a brain, and only those with their volumes no less than T are co Unted. Two pixels are "connected" and hence belong to the same region if they share a common side, as shown from Figure 1 where all The 6 red pixels are connected to the blue one.
Figure 1
Output Specification:
For each case, output in a line the total volume of the stroke core.
Sample Input:
3 4 5 2
1 1 1 1
1 1 1 1
1 1 1 1
0 0 1 1
0 0 1 1
0 0 1 1
1 0 1 1
0 1 0 0
0 0 0 0
1 0 1 1
0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1
1 0 0 0
Sample Output:
26
Given a three-dimensional array, 0 indicates that normal 1 indicates a tumor, the size of the tumor block is greater than or equal to T to be counted as a tumor, so that the calculation of all the size of the tumor block
Analysis: three-dimensional breadth-first search ~~xyz three arrays to determine the direction of each point breadth priority cumulative tumor block size, if greater than or T to add the result. The visit array is used to mark whether the current point has not been accessed, and the node being accessed is no longer accessible. Judge judge whether the boundary is over, or whether the current node is 0 not a tumor ~ ~ ~
#include <cstdio> #include <queue> using namespace std;
struct node {int x, y, z;};
int m, n, L, T;
int x[6] = {1, 0, 0,-1, 0, 0};
int y[6] = {0, 1, 0, 0,-1, 0};
int z[6] = {0, 0, 1, 0, 0,-1};
int arr[1300][130][80];
BOOL Visit[1300][130][80]; BOOL Judge (int x, int y, int z) {if (x < 0 | | x >= m | | y < 0 | | y >= n | | Z < 0 | | z >= l) return F
Alse;
if (arr[x][y][z] = = 0 | | visit[x][y][z] = = true) return false;
return true;
int BFS (int x, int y, int z) {int cnt = 0;
Node temp;
temp.x = x, temp.y = y, temp.z = Z;
Queue<node> Q;
Q.push (temp);
Visit[x][y][z] = true;
while (!q.empty ()) {Node top = Q.front ();
Q.pop ();
cnt++;
for (int i = 0; i < 6; i++) {int tx = top.x + x[i];
int ty = top.y + y[i];
int TZ = top.z + z[i];
if (judge (TX, Ty, TZ)) {Visit[tx][ty][tz] = true; temp.x = tx, temp.y = Ty, temp.z = TZ;
Q.push (temp);
}} if (CNT >= t) return CNT;
else return 0;
int main () {scanf ("%d%d%d%d", &m, &n, &l, &t);
for (int i = 0; i < L; i++) for (int j = 0; J < m; J +) for (int k = 0; k < n; k++)
scanf ("%d", &arr[j][k][i]);
int ans = 0;
for (int i = 0; i < L; i++) {for (int j = 0; J < m; J +) {for (int k = 0; k < n; k++) {
if (arr[j][k][i] = = 1 && visit[j][k][i] = = false) ans + = BFs (j, K, I);
} printf ("%d", ans);
return 0; }