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


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

      识别急性脑卒中(急性脑卒中)的一个重要因素是脑卒中核的体积。根据图像分析的结果,在每个MRI切片中识别核心区域,你的工作就是计算中风核心的体积。

     每个输入文件包含一个测试用例。对于每一种情况,第一行包含4个正整数:m、n、l和t,其中m和n是每片的大小(即一片像素在m乘n矩阵中,最大分辨率为1286乘128);l(<=60)是脑片的数目;t是整数阈值(如果:连接核的体积小于t,那么该核就不能被计算)。然后给出l片。每片用0和1的n矩阵表示,其中1表示笔画的像素,0表示正态。由于切片的厚度是常数,我们只需计算1的数目就可以得到体积。然而,一个大脑中可能有几个分离的核心区域,只有那些体积不小于t的区域才会被计数。如果它们有共同的一面,两个像素是“连接”的,因此属于同一个区域,如图1所示,所有6个红色像素都连接到蓝色像素。

 

#include<cstdio>
#include<queue>
using namespace std;struct Node{int x,y,z;
}node;
int pixel[1290][130][61];
bool inq[1290][130][61] = {false};int n,m,L,T;int X[6] = {0,0,0,0,1,-1};
int Y[6] = {0,0,1,-1,0,0};
int Z[6] = {1,-1,0,0,0,0};
bool judge(int x, int y, int z){if(x >= n || x < 0 || y >= m || y < 0 || z >= L || z < 0)  //x,y,z需要取到n,m,L 从零开始 return false;if(inq[x][y][z] == true || pixel[x][y][z] == 0) //if return fals if  return truereturn false;return true;  
}
int BFS(int x,int y,int z){int tot = 0;node.x = x, node.y = y, node.z = z;queue<Node> q;                      //q的类型是Node 
    q.push(node);inq[x][y][z] = true;while(!q.empty()){Node top = q.front();              //top类型是Node 
        q.pop();tot++;for(int i = 0; i < 6; i++){int newX = top.x + X[i];     //top x,y,z加上方向增量 int newY = top.y + Y[i];int newZ = top.z + Z[i];if(judge(newX,newY,newZ)){node.x = newX,node.y = newY,node.z = newZ;q.push(node);inq[newX][newY][newZ] = true;   //对新节点new入队 2 
            }}}if(tot >= T) return tot;   //要取到等于 else return 0;
}
int main(){scanf("%d%d%d%d",&n,&m,&L,&T);for(int z = 0; z < L; z++){for(int x = 0; x < n; x++){for(int y = 0; y < m; y++){scanf("%d",&pixel[x][y][z]);}}}int ans = 0;for(int z = 0; z < L; z++){for(int x = 0; x < n; x++){for(int y = 0; y < m; y++){if(pixel[x][y][z] == 1 && inq[x][y][z] == false)ans += BFS(x,y,z);}}}printf("%d\n",ans);return 0;
}

 

转载于:https://www.cnblogs.com/wanghao-boke/p/8557015.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/385403.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

lseek函数的使用

需要包含头文件&#xff1a;<sys/types.h> <unistd.h> off_t lseek(int fd, off_t offset, int whence)&#xff1b; 函数原型 函数功能&#xff1a;移动文件读写指针&#xff1b;获取文件长度&#xff1b;拓展文件空间。 在使用该函数之前需要将文件打开&…

19. 删除链表的倒数第N个节点

给定一个链表&#xff0c;删除链表的倒数第 n 个节点&#xff0c;并且返回链表的头结点。 示例&#xff1a; 给定一个链表: 1->2->3->4->5, 和 n 2. 当删除了倒数第二个节点后&#xff0c;链表变为 1->2->3->5. 说明&#xff1a; 给定的 n 保证是有效的。…

文件操作相关的系统函数

重点学习&#xff1a;stat&#xff08;fstat、lstat 获取文件属性&#xff09;、access&#xff08;测试指定文件是否拥有某种权限&#xff09;、chmod&#xff08;改变文件的权限&#xff09;、chown&#xff08;改变文件的所属主和所属组&#xff09;、truncate&#xff08;截…

stat函数(stat、fstat、lstat)

#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> //需包含头文件 有如下三个函数的函数原型&#xff1a; int stat(const char *path, struct stat *buf); 第一个形参&#xff1a;指出文件&#xff08;文件路径&#xff09;&…

1062. Talent and Virtue (25)

About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about peoples talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage&#xff08;圣人&#xff09;"…

access、strtol函数的使用(后者为C库函数)

#include <unistd.h> int access(const char *pathname, int mode); 作用&#xff1a;检查调用该函数的进程是否可以对指定的文件执行某种操作。 第一个形参&#xff1a;文件名&#xff1b;第二个形参&#xff1a;R_OK&#xff08;是否可读&#xff09;、W_OK&#xf…

chmod、chown函数的使用

#include <sys/stat.h> int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); 作用&#xff1a;改变指定文件的权限。第二个参数&#xff1a;mode必须为一个8进制数&#xff1b;返回值为0表示成功&#xff0c;-1表示失败。 //代码 #include…

606. 根据二叉树创建字符串

你需要采用前序遍历的方式&#xff0c;将一个二叉树转换成一个由括号和整数组成的字符串。 空节点则用一对空括号 "()" 表示。而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。 示例 1: 输入: 二叉树: [1,2,3,4] 1 / \ …

truncate、rename函数的使用

#include <unistd.h> #include <sys/types.h> int truncate(const char *path, off_t length); int ftruncate(int fd, off_t length); 作用&#xff1a;用于拓展或截断文件。将参数path 指定的文件大小改为参数length 指定的大小。如果原来的文件大小比参数le…

【Leetcode】112. 路径总和

给定一个二叉树和一个目标和&#xff0c;判断该树中是否存在根节点到叶子节点的路径&#xff0c;这条路径上所有节点值相加等于目标和。 说明: 叶子节点是指没有子节点的节点。 示例: 给定如下二叉树&#xff0c;以及目标和 sum 22&#xff0c; 5 / \ …

link、symlink、readlink、unlink函数的使用

#include <unistd.h> int link(const char *oldpath, const char *newpath); 作用&#xff1a;创建一个硬链接 0成功 -1 失败 //代码 #include <stdio.h> #include <stdlib.h> #include <unistd.h>int main(int argc, char* argv[]) {if(ar…

【Leetcode】113. 路径总和 II

给定一个二叉树和一个目标和&#xff0c;找到所有从根节点到叶子节点路径总和等于给定目标和的路径。 说明: 叶子节点是指没有子节点的节点。 示例: 给定如下二叉树&#xff0c;以及目标和 sum 22&#xff0c; 5 / \ 4 8 / / \ …

目录操作相关的系统函数

主要介绍几个常用函数的使用方法&#xff1a;chdir&#xff08;改变进程的当前工作目录&#xff09;、getcwd&#xff08;获取当前进程的工作目录&#xff09;、mkdir&#xff08;创建目录&#xff09;、rmdir&#xff08;删除空目录&#xff09;、opendir&#xff08;打开一个…

1079. Total Sales of Supply Chain (25)

A supply chain is a network of retailers&#xff08;零售商&#xff09;, distributors&#xff08;经销商&#xff09;, and suppliers&#xff08;供应商&#xff09;-- everyone involved in moving a product from supplier to customer. Starting from one root suppli…

chdir、getcwd、mkdir、rmdir函数

#include <unistd.h> int chdir(const char *path); int fchdir(int fd); 作用&#xff1a;改变调用这一函数的进程&#xff08;即程序执行&#xff09;的当前工作目录&#xff0c;注意不是shell的当前工作目录。 返回值&#xff1a;0成功 -1失败 #include <unis…

【Leetcode | 235】 235. 二叉搜索树的最近公共祖先

给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为&#xff1a;“对于有根树 T 的两个结点 p、q&#xff0c;最近公共祖先表示为一个结点 x&#xff0c;满足 x 是 p、q 的祖先且 x 的深度尽可能大&#xff08;一个节点也可以是它自己…

1090. Highest Price in Supply Chain (25)

A supply chain is a network of retailers&#xff08;零售商&#xff09;, distributors&#xff08;经销商&#xff09;, and suppliers&#xff08;供应商&#xff09;-- everyone involved in moving a product from supplier to customer. Starting from one root suppli…

opendir、readdir和closedir函数

注意&#xff1a;在Linux中&#xff0c;目录的输入格式&#xff1a;/mnt//fghs、/mnt/fghs、/mnt/fghs和/mnt/fghs//是等效的&#xff0c;都一样。 #include <sys/types.h> #include <dirent.h> DIR *opendir(const char *name); DIR *fdopendir(int fd); 返回…

146. LRU缓存机制

运用你所掌握的数据结构&#xff0c;设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作&#xff1a; 获取数据 get 和 写入数据 put 。 获取数据 get(key) - 如果密钥 (key) 存在于缓存中&#xff0c;则获取密钥的值&#xff08;总是正数&#xff09;&#xff…

dup和dup2函数

#include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); 作用&#xff1a;dup函数实现对一个文件的文件描述符进行复制&#xff0c;复制之后该进程就会新增加一一个文件描述符指向该文件&#xff08;即实现同一个文件对应多个文件描述符&#xff0…