天梯题集——肿瘤诊断(三维bfs)

梦里梦外; 2022-12-24 11:57 254阅读 0赞

肿瘤诊断

题目
t2


看到题目第一眼,就害怕了。
上网一查,原来只是个三维 bfs 。
这是一道错过就会后悔的题…
菜是原罪…
bfs模板题


实现代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int m, n, l, t, cnt;
  4. int zl[70][130][1300];
  5. bool judge[70][130][1300]={ false};
  6. int A[6] = { 0, 0, 0, 0, 1, -1};
  7. int B[6] = { 0, 0, 1, -1, 0, 0};
  8. int C[6] = { 1, -1, 0, 0, 0, 0};
  9. struct node{
  10. int a, b, c;
  11. }Node, top;
  12. void bfs(int a, int b, int c){
  13. Node = (node){ a, b, c};
  14. queue <node> q;
  15. q.push(Node);
  16. while(!q.empty()){
  17. top = q.front();
  18. q.pop();
  19. cnt++;
  20. for(int i=0; i<6; i++){
  21. int da = top.a+A[i];
  22. int db = top.b+B[i];
  23. int dc = top.c+C[i];
  24. if(da<=l&&da>0&&db<=m&&db>0&&dc<=n&&dc>0&&
  25. !judge[da][db][dc]&&zl[da][db][dc]){
  26. judge[da][db][dc] = true;
  27. Node = (node){ da, db, dc};
  28. q.push(Node);
  29. }
  30. }
  31. }
  32. return;
  33. }
  34. int main(){
  35. cin>>m>>n>>l>>t;
  36. memset(zl, 0, sizeof(zl));
  37. for(int i=1; i<=l; i++)
  38. for(int j=1; j<=m; j++)
  39. for(int k=1; k<=n; k++)
  40. cin>>zl[i][j][k];
  41. int sum=0;
  42. for(int i=1; i<=l; i++)
  43. for(int j=1; j<=m; j++)
  44. for(int k=1; k<=n; k++){
  45. if(zl[i][j][k]&&!judge[i][j][k]){
  46. cnt = 0;
  47. judge[i][j][k]=true;
  48. bfs(i, j, k);
  49. if(cnt>=t) sum += cnt;
  50. }
  51. }
  52. cout<<sum<<endl;
  53. return 0;
  54. }

发表评论

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

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

相关阅读

    相关 L3-004. 肿瘤诊断

    L3-004. 肿瘤诊断 [题目链接][Link 1] 在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环。给定病灶扫描切片中标注出的疑似肿瘤区域,请