1091. Acute Stroke (30)

Myth丶恋晨 2022-05-28 00:36 204阅读 0赞

One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core.

Input Specification:

Each input file contains one test case. For each case, the first line 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 an M by N matrix, and the maximum resolution is 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 is less than T, then that core must not be counted).

Then L slices are given. Each slice is 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, we only have to count the number of 1’s to obtain the volume. However, there might be several separated core regions in a brain, and only those with their volumes no less than T are counted. Two pixels are “connected” and hence belong to the same region if they share a common side, as shown by Figure 1 where all the 6 red pixels are connected to the blue one.

g0_nf8qpnrr0f1.jpg
Figure 1

Output Specification:

For each case, output in a line the total volume of the stroke core.

Sample Input:

  1. 3 4 5 2
  2. 1 1 1 1
  3. 1 1 1 1
  4. 1 1 1 1
  5. 0 0 1 1
  6. 0 0 1 1
  7. 0 0 1 1
  8. 1 0 1 1
  9. 0 1 0 0
  10. 0 0 0 0
  11. 1 0 1 1
  12. 0 0 0 0
  13. 0 0 0 0
  14. 0 0 0 1
  15. 0 0 0 1
  16. 1 0 0 0

Sample Output:

  1. 26

题目大意:

代码:

  1. #include<stdio.h>
  2. #include<queue>
  3. using namespace std;
  4. int n,m,k,t;
  5. int arr[1300][130][80];
  6. int visited[1300][130][80];
  7. int X[6] = {1, 0, 0, -1, 0, 0};
  8. int Y[6] = {0, 1, 0, 0, -1, 0};
  9. int Z[6] = {0, 0, 1, 0, 0, -1};
  10. struct node
  11. {
  12. int a,b,c;
  13. };
  14. int judge(int x,int y,int z)
  15. {
  16. if(x<0||x>=n||y<0||y>=m||z<0||z>=k)
  17. return 0;
  18. else if(arr[x][y][z]==0||visited[x][y][z]==1)
  19. return 0;
  20. else
  21. return 1;
  22. }
  23. int BFS(int x,int y,int z)
  24. {
  25. struct node tmp;
  26. int num=0;
  27. tmp.a=x;
  28. tmp.b=y;
  29. tmp.c=z;
  30. queue<struct node> q;
  31. q.push(tmp);
  32. visited[x][y][z]=1;
  33. while(!q.empty())
  34. {
  35. num++;
  36. struct node top=q.front();
  37. q.pop();
  38. for(int i=0;i<6;i++)
  39. {
  40. int tx=top.a+X[i];
  41. int ty=top.b+Y[i];
  42. int tz=top.c+Z[i];
  43. if(judge(tx,ty,tz)==1)
  44. {
  45. visited[tx][ty][tz]=1;
  46. tmp.a=tx;
  47. tmp.b=ty;
  48. tmp.c=tz;
  49. q.push(tmp);
  50. }
  51. }
  52. }
  53. if(num>=t)
  54. return num;
  55. else
  56. return 0;
  57. }
  58. int main()
  59. {
  60. int i,j,l,total=0;
  61. scanf("%d %d %d %d",&n,&m,&k,&t);
  62. for(i=0;i<k;i++)
  63. {
  64. for(j=0;j<n;j++)
  65. {
  66. for(l=0;l<m;l++)
  67. {
  68. scanf("%d",&arr[j][l][i]);
  69. }
  70. }
  71. }
  72. for(i=0;i<k;i++)
  73. {
  74. for(j=0;j<n;j++)
  75. {
  76. for(l=0;l<m;l++)
  77. {
  78. if(arr[j][l][i]==1&&visited[j][l][i]==0)
  79. total+=BFS(j,l,i);
  80. }
  81. }
  82. }
  83. printf("%d\n",total);
  84. return 0;
  85. }

发表评论

表情:
评论列表 (有 0 条评论,204人围观)

还没有评论,来说两句吧...

相关阅读

    相关 P1091 合唱队形

    题目描述 NNN位同学站成一排,音乐老师要请其中的(N−KN-KN−K)位同学出列,使得剩下的KKK位同学排成合唱队形。 合唱队形是指这样的一种队形:设K位同学从左到右

    相关 stroke方法怎么使用

    stroke方法怎么使用 stroke() 方法会实际地绘制出通过moveTo() 和lineTo()方法定义的路径,默认颜色是黑色。下面我们就来具体看看stroke()...