当前位置: 首页 > news >正文

1091 Acute Stroke (30)

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×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×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.

figstroke.jpg

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

 题目大意:给定一个三维数组,0 表示正常, 1 表示有肿瘤,肿瘤块的大小大于等于 t 才算作是肿瘤,求所有满足大小大于 t 的肿瘤块的总大小。
分析:BFS。总共有 6 个方向,从某个值为 1 的点开始进行 BFS,返回这个块的大小。遍历完整个三维数组即可。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0x3fffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
#define NUMBER_OF_THREADS   10
using namespace std;int matrix[65][1290][130],flag[65][1290][130];
int dir_z[]={1,-1,0,0,0,0},dir_x[]={0,0,1,-1,0,0},dir_y[]={0,0,0,0,1,-1};typedef struct node
{int x,y,z;
}node;int bfs(int z,int x,int y)
{int cnt=0;node sta;sta.x=x,sta.y=y,sta.z=z;queue<node>que;que.push(sta);while(!que.empty()){node temp=que.front();que.pop();cnt++;for(int i=0;i<6;++i){node val=temp;val.x+=dir_x[i],val.y+=dir_y[i],val.z+=dir_z[i];if(matrix[val.z][val.x][val.y]==1&&flag[val.z][val.x][val.y]==0)flag[val.z][val.x][val.y]=1,que.push(val);}}return cnt;
}int main(void)
{#ifdef testfreopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);clock_t start=clock();#endif //testint m,n,l,t;scanf("%d%d%d%d",&m,&n,&l,&t);for(int z=1;z<=l;++z)for(int x=1;x<=m;++x)for(int y=1;y<=n;++y)scanf("%d",&matrix[z][x][y]),flag[z][x][y]=0;int ans=0;for(int z=1;z<=l;++z){for(int x=1;x<=m;++x){for(int y=1;y<=n;++y){if(!flag[z][x][y]){flag[z][x][y]=1;if(matrix[z][x][y]==1){int cnt=bfs(z,x,y);if(cnt>=t)ans+=cnt;}}}}}printf("%d\n",ans);#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

http://www.xdnf.cn/news/949555.html

相关文章:

  • 2025年全国I卷数学压轴题解答
  • 大模型链路调试平台之LangSmith实战指南
  • Web 架构之 API 安全防护:防刷、防爬、防泄漏
  • SpringBoot整合SSM
  • React中子传父组件通信操作指南
  • 使用VBA嵌套字典快速转换BOM表格
  • 鸢尾花分类(KNN)
  • 【AI News | 20250609】每日AI进展
  • 测试微信模版消息推送
  • 开源:FTP同步工具
  • 【粤语克隆】粤语声音,一秒克隆:如何用AI为岭南文化按下快进键
  • composer init
  • LeetCode - 647. 回文子串
  • 具身智能之人形机器人核心零部件介绍
  • 教程:PyCharm 中搭建多级隔离的 Poetry 环境(从 Anaconda 到项目专属.venv)
  • 重启Eureka集群中的节点,对已经注册的服务有什么影响
  • 深入理解JavaScript设计模式之单例模式
  • AirPosture | 通过 AirPods 矫正坐姿
  • 安科瑞户储ADL200N-CT:即插即用破解家庭光伏安装困局
  • HBase学习:通俗易懂的实例解析
  • K8S认证|CKS题库+答案| 10. Trivy 扫描镜像安全漏洞
  • Java中HashMap底层原理深度解析:从数据结构到红黑树优化
  • 人工智能 - 在Dify、Coze、n8n、FastGPT和RAGFlow之间做出技术选型
  • Excel处理控件Aspose.Cells教程:在Excel 文件中创建、操作和渲染时间线
  • 国内外UI自动化测试工具全景分析:国产创新与国际领先工具对比
  • Rougamo.Fody 实现一个AOP日志
  • UI框架-通知组件
  • TMC2226超静音步进电机驱动控制模块
  • 高抗扰度汽车光耦合器的特性
  • 渗透实战PortSwigger Labs指南:自定义标签XSS和SVG XSS利用