- Topic address
- Title analysis: Now we find that reading is really a problem worthy of serious consideration! Secondly, I will give two solutions to this question, only the operation changes of the upper and lower displacement modes. (Thank you. LiuChuo)
-
The title is translated as follows:
Acute stroke
One of the important means to identify acute stroke is to determine the volume of the stroke core. The title gives an image result defined in the analysis of the core area of each MRI slice. You need to calculate the volume of the stroke core.
Input format:
Each input file contains a test case. In each test case, the first line gives four positive integers: M, N, L and T, where M and N are the size of each slice (e.g., a slice's pixel is a rectangle of M*N with a maximum resolution of 1280*128); L(<=60) is the total number of slices of the brain; T is the integer threshold (e.g., if a connected core body) If the product is less than T, then the core should not be counted.Then L slices are given. Each slice consists of a rectangle of M*N represented by 0 or 1, where 1 represents the stroke of the pixel and 0 represents the normal point. Since the thickness of a slice is constant, we only need to count the number of 1 to get the volume size. However, there may be some separate core areas in the brain, but we only count the stroke core whose volume is not less than T. Two pixels connected belong to a region (core discourse), if they share one side, the six pixels shown in the figure are connected by blue pixels.
Output format:
For each case, output the total volume of all stroke cores in one row.
- My code:
#include<iostream> #include<queue> using namespace std; int m, n, l, t, TOL = 0; bool aa[60][1286][128] = { 0 }, bb[60][1286][128] = { 0 }; queue<int>ql, qm, qn; void bfs(int i, int j, int k); void pus(int i, int j, int k) { ql.push(i), qm.push(j), qn.push(k); } void get(int *ii, int *jj, int *kk) { *ii = ql.front(), *jj = qm.front(), *kk = qn.front(); ql.pop(), qm.pop(), qn.pop(); } void opt(int ii, int jj, int kk, int *tol); 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, val; k < n; k++) { scanf("%d", &val); val ? aa[i][j][k] = true : false; } for (int i = 0; i < l; i++) for (int j = 0; j < m; j++) for (int k = 0; k < n; k++) if (aa[i][j][k] && !bb[i][j][k]) { bb[i][j][k] = true; pus(i, j, k); bfs(i, j, k); } printf("%d", TOL); return 0; } void bfs(int i, int j, int k) { int ii, jj, kk, tol = 1; while (ql.size()) { get(&ii, &jj, &kk); opt(ii - 1, jj, kk, &tol), opt(ii + 1, jj, kk, &tol); opt(ii, jj - 1, kk, &tol), opt(ii, jj + 1, kk, &tol); opt(ii, jj, kk - 1, &tol), opt(ii, jj, kk + 1, &tol); } if (tol >= t) TOL += tol; return; } void opt(int ii, int jj, int kk, int *tol) { if (ii >= 0 && jj >= 0 && kk >= 0 && ii < l && jj < m && kk < n && aa[ii][jj][kk] && !bb[ii][jj][kk]) { bb[ii][jj][kk] = true; pus(ii, jj, kk); (*tol)++; } return; }
#include<iostream> #include<queue> using namespace std; int m, n, l, t, TOL = 0, z[6] = { 1,-1,0,0,0,0 }, x[6] = { 0,0,1,-1,0,0 }, y[6] = { 0,0,0,0,1,-1 }; bool aa[60][1286][128] = { 0 }, bb[60][1286][128] = { 0 }; struct node { int x, y, z; }; queue<node>qq; void bfs(int i, int j, int k); bool jud(int tz, int tx, int ty) { if (tz < 0 || tx < 0 || ty < 0 || tz >= l || tx >= m || ty >= n) return false; if (!aa[tz][tx][ty] || bb[tz][tx][ty]) return false; return true; } 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, val; k < n; k++) { scanf("%d", &val); val ? aa[i][j][k] = true : false; } for (int i = 0; i < l; i++) for (int j = 0; j < m; j++) for (int k = 0; k < n; k++) if (aa[i][j][k] && !bb[i][j][k]) { bb[i][j][k] = true; bfs(i, j, k); } printf("%d", TOL); return 0; } void bfs(int i, int j, int k) { int tol = 1; node temp; temp.z = i, temp.x = j, temp.y = k; qq.push(temp); while (qq.size()) { node top = qq.front(); qq.pop(); for (int i = 0; i < 6; i++) { int tz = top.z + z[i]; int tx = top.x + x[i]; int ty = top.y + y[i]; if (jud(tz, tx, ty)) { bb[tz][tx][ty] = true; tol++; temp.z = tz, temp.x = tx, temp.y = ty; qq.push(temp); } } } if (tol >= t) TOL += tol; return; }