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.pswp.cn/news/385403.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/385403.shtml
英文地址,請注明出處:http://en.pswp.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…