PAT1091Acute Stroke

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
思想:正常的进队入队搜索的思路,需要注意的一点是此题是三维坐标。一维是横坐标,二维是纵坐标,三维是纵轴。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <queue>
 4 using namespace std;
 5 #define C 65
 6 #define A 1290
 7 #define B 130
 8 int pixel[A][B][C];
 9 bool pixelif[A][B][C]={
10     false
11 };
12 struct Node
13 {
14     int x,y,z;
15 }node;
16 int M,N,L,T;
17 int X[6]={
18     0,0,0,0,1,-1
19 };
20 int Y[6]={
21     0,0,1,-1,0,0
22 };
23 int Z[6]={
24     1,-1,0,0,0,0
25 };
26 bool Judge(int x,int y,int z)
27 {
28     if(x<0||x>=M||y<0||y>=N||z<0||z>=L)
29       return false;
30     if(pixel[x][y][z]==0||pixelif[x][y][z]==true)
31       return false;
32     return true;
33 }
34 int BFS(int z,int x,int y)
35 {
36     int total=0;
37     queue<Node> Q;
38     node.z=z;
39     node.x=x;
40     node.y=y;
41     Q.push(node);
42     pixelif[x][y][z]=true;
43     while(!Q.empty())
44     {
45         Node top=Q.front();//没有front。。。
46         Q.pop();
47         total++;
48         for(int i=0;i<6;i++)
49         {
50             int newX=top.x+X[i];
51             int newY=top.y+Y[i];
52             int newZ=top.z+Z[i];
53             if(Judge(newX,newY,newZ))
54             {
55                 node.x=newX;
56                 node.y=newY;
57                 node.z=newZ;
58                 Q.push(node);
59                 pixelif[newX][newY][newZ]=true;
60             }
61         }
62     }
63     if(total<T)
64       return 0;
65     else
66       return total;
67 }
68 int main(int argc, char *argv[])
69 {
70     scanf("%d%d%d%d",&M,&N,&L,&T);
71     for(int i=0;i<L;i++)
72     {
73         for(int j=0;j<M;j++)
74         {
75             for(int k=0;k<N;k++)
76             {
77                 scanf("%d",&pixel[j][k][i]);
78             }
79         }
80     }
81     int ans=0;
82     for(int z=0;z<L;z++)
83     {
84         for(int x=0;x<M;x++)
85         {
86             for(int y=0;y<N;y++)
87             {
88                 if(pixelif[x][y][z]==false&&pixel[x][y][z]==1)
89                 {
90                     ans+=BFS(z,x,y);
91                 }
92             }
93         }
94     }
95     printf("%d\n",ans);
96     return 0;
97 }

时间: 2024-10-23 06:23:14

PAT1091Acute Stroke的相关文章

PAT 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. 输入描述:

hzau 1203 One Stroke

1203: One Stroke Time Limit: 2 Sec  Memory Limit: 1280 MBSubmit: 264  Solved: 56[Submit][Status][Web Board] Description There is a complete binary tree which includes n nodes. Each node on the tree has a weight w, each edge on the tree is directed fr

PAT-ADVANCED-1091-Acute Stroke

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 Spec

pat1091. Acute Stroke (30)

1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 iden

android stroke描边,去掉左右描边

一般描边开始: <shape xmlns:android="http://schemas.android.com/apk/res/android">          <stroke android:width="1dp" android:color="@color/line" /> </shape> 去掉左右描边: <layer-list xmlns:android="http://schem

HTML5 Canvas ( 线段的绘制 ) beginPath, moveTo, strokeStyle, stroke

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>canvas</title> <script type="text/javascript" src="../js/jQuery.js"></script> <style type="text/css">

iOS 2D绘图 (Quartz2D)之路径(stroke,fill,clip,subpath,blend)

像往常一样 这个系列的博客是跟着大神的脚步来的.按照往例 在此贴出原博客的出处: http://blog.csdn.net/hello_hwc?viewmode=list 我对大神的崇拜之情 如滔滔江水 巴拉巴拉的 ......... 言归正传 Stroke-描边 影响描边的因素 线的宽度-CGContextSetLineWidth 交叉线的处理方式-CGContextSetLineJoin 线顶端的处理方式-CGContextSetLineCap 进一步限制交叉线的处理方式-CGContext

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

Samurai&amp;#39;s Stroke

题目链接 题意: 一个长度为L的木棍,有n个支点支撑,每一个点是一个int数.表示距离木棍左端点的距离.求在那些位置将木棍劈开能够使得至少有一个木棍掉下去,输出这些位置的长度 3 ≤ l ≤ 109; 2 ≤ n ≤ 105 分析: 对于左端的木棍.假设会掉下去一定是重心在木棍之外.两种情况:1,在最左端木棍之外.2,在最右木棍之外 每次能够得到一个答案区间,最后再从右向左处理一下,将区间合并即答案 const int maxn = 1100000; struct Seg { int l, r;