PAT(A) - 1091. Acute Stroke (30)
来源:互联网 发布:tensorflow optimizer 编辑:程序博客网 时间:2024/04/29 13:20
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 21 1 1 11 1 1 11 1 1 10 0 1 10 0 1 10 0 1 11 0 1 10 1 0 00 0 0 01 0 1 10 0 0 00 0 0 00 0 0 10 0 0 11 0 0 0Sample Output:
26
思路分析:第一次做这种三维的BFS,虽然思路是一样的,但还是没写出来.....英语也不好理解。参考了网上别人的题解。
#include <cstdio>#include <queue>using namespace std;int MGraph[1290][130][61];int visit[1290][130][61];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 };int m, n, l, T;typedef struct Point { Point( int xx, int yy, int zz ) { x = xx; y = yy; z = zz; } int x; int y; int z;} Point;bool judge( Point p ) { // 越界 if( p.x >= m || p.x < 0 || p.y >= n || p.y < 0 || p.z >= l || p.z < 0 ) return false; // 0的区域不可访问 if( MGraph[p.x][p.y][p.z] == 0 ) return false; // 已经访问过 if( visit[p.x][p.y][p.z] ) return false; // 其他情况返回true return true;}int bfs( Point start ) { queue<Point> q; q.push( start ); visit[start.x][start.y][start.z] = 1; int tot = 0; while( !q.empty() ) { Point cur = q.front(); q.pop(); tot++; for( int i = 0; i < 6; i++ ) { // 枚举6个方向 int newX = cur.x + X[i]; int newY = cur.y + Y[i]; int newZ = cur.z + Z[i]; Point p( newX, newY, newZ ); if( judge( p ) ) { q.push( p ); visit[p.x][p.y][p.z] = 1; } } } return tot;}int main() { scanf( "%d%d%d%d", &m, &n, &l, &T ); for( int i = 0; i < l; i++ ) for( int j = 0; j < m; j++ ) for( int k = 0; k < n; k++ ) { scanf( "%d", &MGraph[j][k][i] ); } int sum = 0; for( int i = 0; i < l; i++ ) for( int j = 0; j < m; j++ ) for( int k = 0; k < n; k++ ) { if( !visit[j][k][i] && MGraph[j][k][i] == 1 ) { Point p( j, k, i ); int ans = bfs( p ); if( ans >= T ) { // 大于等于阈值累计和 sum += ans; } } } printf( "%d\n", sum ); return 0;}
- PAT A 1091. Acute Stroke (30)
- PAT(A) - 1091. Acute Stroke (30)
- PAT-A-1091. Acute Stroke (30)
- Pat(A) 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)
- 【PAT】1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke
- 【PAT】1091. Acute Stroke
- PAT Acute Stroke (30)
- pat- Acute Stroke (30)
- PAT-A | 1091 | Acute Stroke
- PAT(Advance) 1091. Acute Stroke (30)
- PAT 1091. Acute Stroke (30)(孤岛问题)
- PAT--1091. Acute Stroke (30)(三维bfs)
- 1091. Acute Stroke (30) PAT甲级
- 【PAT】【Advanced Level】1091. Acute Stroke (30)
- pip win10 升级问题
- Codeforces Round #383 (Div. 2) C. Arpa's loud Owf and Mehrdad's evil plan
- STM32F412应用开发笔记之一:初识NUCLEO-F412ZG
- 332. Reconstruct Itinerary
- openstack的常用命令
- PAT(A) - 1091. Acute Stroke (30)
- VHDL
- LeetCode445. Add Two Numbers II
- DAVID java webservice相关
- 不是内部或外部命令也不是可运行的程序或批处理
- google浏览器更改右侧滚动条代码
- PAT乙级 1019. 数字黑洞 (20)
- linux webbench测试高并发方法
- 内部类详解【转】