1091. Acute Stroke (30)
2016-07-28 16:34
465 查看
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:
Sample Output:
题目意思太难搞懂了,我也不好描述这些医学的东西。换种数学的说法来说,就是一个三维图形,其中相连的点组成一个集合,如果集合大小大于等于t就是符合条件。求符合条件的集合的大小的总和。先用三维数组储存点的信息,然后用dfs遍历,求出所有连通集合,然后将大小大于等于t的集合的大小累加得到答案,这样最后两个case过不了,可能是因为六个方向递归搜索有点吃力。改用bfs即可通过。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;
int m,n,l,t;
vector<vector<vector<int> > >a;
vector<vector<vector<bool> > >isvis;
int dir1[6]={1,0,0,-1,0,0};
int dir2[6]={0,1,0,0,-1,0};
int dir3[6]={0,0,1,0,0,-1};
/*
void dfs(int i,int j,int k,int &count)
{
isvis[i][j][k]=true;
count++;
for(int p=0;p<6;p++)
{
int x=i+dir1[p],y=j+dir2[p],z=k+dir3[p];
if(x>=0&&y>=0&&z>=0&&x<l&&y<m&&z<n&&!isvis[x][y][z]&&a[x][y][z]==1)
{
dfs(x,y,z,count);
}
}
}
*/
struct point
{
int x,y,z;
point(int xx,int yy,int zz):x(xx),y(yy),z(zz){}
};
int main()
{
cin>>m>>n>>l>>t;
a.resize(l,vector<vector<int> >(m,vector<int>(n,0)));
for(int i=0;i<l;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
cin>>a[i][j][k];
}
}
}
isvis.resize(l,vector<vector<bool> >(m,vector<bool>(n,false)));
int res=0;
for(int i=0;i<l;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
if(!isvis[i][j][k]&&a[i][j][k]==1)
{
int count=0;
//dfs(i,j,k,count);
queue<point>que;
que.push(point(i,j,k));
isvis[i][j][k]=true;
while(!que.empty())
{
point tmp=que.front();
que.pop();
count++;
for(int p=0;p<6;p++)
{
int x=tmp.x+dir1[p],y=tmp.y+dir2[p],z=tmp.z+dir3[p];
if(x>=0&&y>=0&&z>=0&&x<l&&y<m&&z<n&&!isvis[x][y][z]&&a[x][y][z]==1)
{
isvis[x][y][z]=true;
que.push(point(x,y,z));
}
}
}
if(count>=t) res+=count;
}
}
}
}
cout<<res;
}
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
题目意思太难搞懂了,我也不好描述这些医学的东西。换种数学的说法来说,就是一个三维图形,其中相连的点组成一个集合,如果集合大小大于等于t就是符合条件。求符合条件的集合的大小的总和。先用三维数组储存点的信息,然后用dfs遍历,求出所有连通集合,然后将大小大于等于t的集合的大小累加得到答案,这样最后两个case过不了,可能是因为六个方向递归搜索有点吃力。改用bfs即可通过。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;
int m,n,l,t;
vector<vector<vector<int> > >a;
vector<vector<vector<bool> > >isvis;
int dir1[6]={1,0,0,-1,0,0};
int dir2[6]={0,1,0,0,-1,0};
int dir3[6]={0,0,1,0,0,-1};
/*
void dfs(int i,int j,int k,int &count)
{
isvis[i][j][k]=true;
count++;
for(int p=0;p<6;p++)
{
int x=i+dir1[p],y=j+dir2[p],z=k+dir3[p];
if(x>=0&&y>=0&&z>=0&&x<l&&y<m&&z<n&&!isvis[x][y][z]&&a[x][y][z]==1)
{
dfs(x,y,z,count);
}
}
}
*/
struct point
{
int x,y,z;
point(int xx,int yy,int zz):x(xx),y(yy),z(zz){}
};
int main()
{
cin>>m>>n>>l>>t;
a.resize(l,vector<vector<int> >(m,vector<int>(n,0)));
for(int i=0;i<l;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
cin>>a[i][j][k];
}
}
}
isvis.resize(l,vector<vector<bool> >(m,vector<bool>(n,false)));
int res=0;
for(int i=0;i<l;i++)
{
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
if(!isvis[i][j][k]&&a[i][j][k]==1)
{
int count=0;
//dfs(i,j,k,count);
queue<point>que;
que.push(point(i,j,k));
isvis[i][j][k]=true;
while(!que.empty())
{
point tmp=que.front();
que.pop();
count++;
for(int p=0;p<6;p++)
{
int x=tmp.x+dir1[p],y=tmp.y+dir2[p],z=tmp.z+dir3[p];
if(x>=0&&y>=0&&z>=0&&x<l&&y<m&&z<n&&!isvis[x][y][z]&&a[x][y][z]==1)
{
isvis[x][y][z]=true;
que.push(point(x,y,z));
}
}
}
if(count>=t) res+=count;
}
}
}
}
cout<<res;
}
相关文章推荐
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- js算法: 图的两种表示方法以及广度优先算法
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- Hadoop FS Shell
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- POJ1523 SPF dfs
- poj1731 Orders dfs
- 【日常练习】Prime Ring Problem(素数环)
- 【日常练习 搜索】诡异的楼梯(队列+bfs)
- Surrounded Regions
- Word Ladder, Gray Code
- Microsoft Windows Server 2003 R2 分布式文件系统解决方案概述