1091. Acute Stroke (30)

102 篇文章 0 订阅
37 篇文章 0 订阅

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;起初异常的坐标都记录在和里面

评测结果

时间 结果 得分 题目 语言 用时(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答案正确301091C++ (g++ 4.7.2)21012808datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确130815/15
1答案正确13086/6
2答案正确13082/2
3答案正确11802/2
4答案正确210128082/2
5答案正确20066963/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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值