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 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
下面两个代码的区别是一个用了符号重载;
M N L T(L个M行N列的长方体)
接着就是L个M行N列的输入;0代表正常,1代表异常;而造成病变的,是一块的异常总数>=T;
PS:一块的意思是只要上下左右前后有是异常的就加起来。
这里用的是BFS,对于每个左标,进行上下左右前后,在范围内的异常的进行累加,并扩展的一块之外都是正常,然后看看这一块的异常总数是不是>=T;是就是病变加到core里面
vector<vector<vector<bool>>>cuboid(L);长方体
vector< index_z_y_x>z_y_x;起初异常的坐标都记录在和里面
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.
![](http://www.patest.cn/upload/g0_nf8qpnrr0f1.jpg)
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 0Sample Output:
26
下面两个代码的区别是一个用了符号重载;
M N L T(L个M行N列的长方体)
接着就是L个M行N列的输入;0代表正常,1代表异常;而造成病变的,是一块的异常总数>=T;
PS:一块的意思是只要上下左右前后有是异常的就加起来。
这里用的是BFS,对于每个左标,进行上下左右前后,在范围内的异常的进行累加,并扩展的一块之外都是正常,然后看看这一块的异常总数是不是>=T;是就是病变加到core里面
vector<vector<vector<bool>>>cuboid(L);长方体
vector< index_z_y_x>z_y_x;起初异常的坐标都记录在和里面
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月19日 00:21 | 答案正确 | 30 | 1091 | C++ (g++ 4.7.2) | 219 | 12824 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 180 | 15/15 |
1 | 答案正确 | 1 | 304 | 6/6 |
2 | 答案正确 | 1 | 384 | 2/2 |
3 | 答案正确 | 1 | 252 | 2/2 |
4 | 答案正确 | 219 | 12824 | 2/2 |
5 | 答案正确 | 200 | 6728 | 3/3 |
#include<iostream> #include<vector> #include<queue> using namespace std; struct index_z_y_x { int x; int y; int z; index_z_y_x(){} index_z_y_x(int zz, int yy, int xx) :x(xx), y(yy), z(zz) {} }; void readln(vector<vector<vector<bool>>>*cuboid, int N, int M, int L, vector< index_z_y_x>*z_y_x) { int temp, xx, yy, zz; for (zz = 0; zz < L; zz++) { (*cuboid)[zz].resize(M); for (yy = 0; yy < M; yy++) { (*cuboid)[zz][yy].resize(N); for (xx = 0; xx < N; xx++) { cin >> temp; if (1 == temp) { (*cuboid)[zz][yy][xx] = true; z_y_x->push_back(index_z_y_x(zz, yy, xx)); } else (*cuboid)[zz][yy][xx] = false; } } } } void BFScount(vector<vector<vector<bool>>>*cuboid, int N, int M, int L,int T, int *count, index_z_y_x*direction,index_z_y_x nowzyx) { queue<index_z_y_x>Q; Q.push(nowzyx); (*count)++; (*cuboid)[nowzyx.z][nowzyx.y][nowzyx.x] = false; while (!Q.empty()) { nowzyx = Q.front(); Q.pop(); for (int index = 0; index < 6; index++) { index_z_y_x temp; temp.x = nowzyx.x + direction[index].x; temp.y = nowzyx.y + direction[index].y; temp.z = nowzyx.z + direction[index].z; if (temp.x >= 0 && temp.x < N&&temp.y >= 0 && temp.y < M&&temp.z < L&&temp.z>=0&& (*cuboid)[temp.z][temp.y][temp.x]) { Q.push(temp); (*cuboid)[temp.z][temp.y][temp.x] = false; (*count)++; } } } if ((*count) < T)(*count) = 0; } int main() { int N, M, L, T, core, count; cin >> M >> N >> L >> T; vector<vector<vector<bool>>>cuboid(L); vector< index_z_y_x>z_y_x; index_z_y_x direction[6] = { index_z_y_x(0, 0, 1), index_z_y_x(0, 0, -1), index_z_y_x(0, 1, 0), index_z_y_x(0, -1, 0), index_z_y_x (1, 0, 0), index_z_y_x(-1, 0, 0) }; readln(&cuboid, N, M, L, &z_y_x); core = 0; for (vector<index_z_y_x>::iterator iter = z_y_x.begin(); iter != z_y_x.end(); iter++) { count = 0; if (cuboid[iter->z][iter->y][iter->x]) BFScount(&cuboid, N, M, L,T, &count,direction,(*iter)); core += count; } cout << core << endl; system("pause"); return 0; }
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月19日 00:26 | 答案正确 | 30 | 1091 | C++ (g++ 4.7.2) | 210 | 12808 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 308 | 15/15 |
1 | 答案正确 | 1 | 308 | 6/6 |
2 | 答案正确 | 1 | 308 | 2/2 |
3 | 答案正确 | 1 | 180 | 2/2 |
4 | 答案正确 | 210 | 12808 | 2/2 |
5 | 答案正确 | 200 | 6696 | 3/3 |
#include<iostream> #include<vector> #include<queue> using namespace std; struct index_z_y_x { int x; int y; int z; index_z_y_x(){} index_z_y_x(int zz, int yy, int xx) :x(xx), y(yy), z(zz) {} void operator+(index_z_y_x temp) { this->x += temp.x; this->y += temp.y; this->z += temp.z; } }; void readln(vector<vector<vector<bool>>>*cuboid, int N, int M, int L, vector< index_z_y_x>*z_y_x) { int temp, xx, yy, zz; for (zz = 0; zz < L; zz++) { (*cuboid)[zz].resize(M); for (yy = 0; yy < M; yy++) { (*cuboid)[zz][yy].resize(N); for (xx = 0; xx < N; xx++) { cin >> temp; if (1 == temp) { (*cuboid)[zz][yy][xx] = true; z_y_x->push_back(index_z_y_x(zz, yy, xx)); } else (*cuboid)[zz][yy][xx] = false; } } } } void BFScount(vector<vector<vector<bool>>>*cuboid, int N, int M, int L,int T, int *count, index_z_y_x*direction,index_z_y_x nowzyx) { queue<index_z_y_x>Q; Q.push(nowzyx); (*count)++; (*cuboid)[nowzyx.z][nowzyx.y][nowzyx.x] = false; while (!Q.empty()) { nowzyx = Q.front(); Q.pop(); for (int index = 0; index < 6; index++) { index_z_y_x temp=nowzyx; temp + direction[index];/*重载了+*/ if (temp.x >= 0 && temp.x < N&&temp.y >= 0 && temp.y < M&&temp.z < L&&temp.z>=0&& (*cuboid)[temp.z][temp.y][temp.x]) { Q.push(temp); (*cuboid)[temp.z][temp.y][temp.x] = false; (*count)++; } } } if ((*count) < T)(*count) = 0; } int main() { int N, M, L, T, core, count; cin >> M >> N >> L >> T; vector<vector<vector<bool>>>cuboid(L); vector< index_z_y_x>z_y_x; index_z_y_x direction[6] = { index_z_y_x(0, 0, 1), index_z_y_x(0, 0, -1), index_z_y_x(0, 1, 0), index_z_y_x(0, -1, 0), index_z_y_x (1, 0, 0), index_z_y_x(-1, 0, 0) }; readln(&cuboid, N, M, L, &z_y_x); core = 0; for (vector<index_z_y_x>::iterator iter = z_y_x.begin(); iter != z_y_x.end(); iter++) { count = 0; if (cuboid[iter->z][iter->y][iter->x]) BFScount(&cuboid, N, M, L,T, &count,direction,(*iter)); core += count; } cout << core << endl; system("pause"); return 0; }