Pat 1091__, Zhejiang, Pat

Source: Internet
Author: User
1091. Acute Stroke ()Time limit MS
Memory Limit 65536 KB
Code length limit 16000 B
Standard author CHEN, Yue

One important factor to identify acute stroke (acute stroke) is the volume core. Given the results of image analysis into which the core regions are identified in each MRI slice, your job are to calculate t He volume the stroke core.

Input Specification:

Each input file contains one test case. For each case, the 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 a M by N matrix, and the maximum resolution be 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 are less than T, then that core must isn't be counted) .

Then L slices are given. Each slice was 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 and we only have to count the number of 1 's to obtain the volume. However, there might is several separated core regions in a brain, and only those with their volumes no less than T are co Unted. Two pixels are "connected" and hence belong to the same region if they share a common side, as shown from 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.

Analysis: The topic is too abstract, opened a lot of times, that is, there are slices in the head, gave L each for the m*n matrix, the maximum does not exceed 1280*128, the highest not more than 60;

Then the key is, if a point is 1, then find the store 3-dimensional all 1 points, if their sum is greater than t, is entered;

At first see also thought is each column is bigger than T, OK; here for reference to the years of code, the key is three-dimensional space bfs;

#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue
> #include <stdio.h> using namespace std;
int m,n,l,t;
int total=0;  
int matrix[1286][128][60];  
int xx[6] = {1,-1,0,0,0,0};  
int yy[6] = {0,0,1,-1,0,0};  
int zz[6] = {0,0,0,0,1,-1};  
    struct node{int x, y, Z;  
Node (int _x, int _y, int _z) {x=_x; y=_y; z=_z;
	void BFs (int x,int y,int z) {queue<node> q;
	Q.push (Node (x,y,z));
	int cnt=1;
		while (!q.empty ()) {node No=q.front ();
			for (int i=0;i<6;i++) {int tx=no.x+xx[i];
			int ty=no.y+yy[i];
			int tz=no.z+zz[i]; if ((tx>=0&&tx<m) &&ty>=0&&ty<n&&tz>=0&&tz<l&&
					matrix[tx][ty][tz]==1) {cnt++;
				Q.push (Node (TX,TY,TZ));
	} q.pop ();
} if (cnt>=t) total+=cnt; int main () {//int **a=new int *[m];//for (int i=0;i< m;i++)//a[i]=new int[n]; 
	for (int i=0;i<m;i++)//for (int j=0;j<n;j++)//cin>>a[i][j];
	cin>>m>>n>>l>>t; for (int i=0;i<l;i++) {for (int kk=0;kk<m;kk++) {for (int j=0;j<n;j++) {scanf ("%d")
				; matrix[kk][j][i]);
					(int i=0;i<m;i++) for (int j=0;j<n;j++) for (int w=0;w<l;w++) if (matrix[i][j][w]==1)
	BFS (I,J,W);
return 0;  }

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.