GPLT L3-004. 肿瘤诊断【三维bfs求连通块】
来源:互联网 发布:云计算与虚拟化的区别 编辑:程序博客网 时间:2024/05/19 13:10
题目:肿瘤诊断
题意:找三维图中的连通块的面积,即1的个数 连通块有个要求如果小于给定的范围就不计!
思路:开始时用dfs做,栈溢出了。。。数据大了!
换成bfs寻找连通即可!
代码:
#include <stdio.h>#include <cstring>#include <queue>using namespace std;const int row = 1500;const int col = 200;const int heg = 100;const int dirx[] = {1,-1,0,0,0,0};const int diry[] = {0,0,-1,1,0,0};const int dirz[] = {0,0,0,0,1,-1};int g[heg][row][col];int n,m,l,t,cnt;struct node{ int x,y,z; node(int tx,int ty,int tz):x(tx),y(ty),z(tz){};};void bfs(int sz,int sx,int sy){ g[sz][sx][sy] = 0; queue<node>Q; Q.push(node(sx,sy,sz)); while(!Q.empty()){ node pre = Q.front();Q.pop(); for(int i=0;i<6;i++){ int tx = pre.x+dirx[i] , ty = pre.y+diry[i] , tz = pre.z + dirz[i]; if(tx < 0 || tx >= n || ty < 0 || ty >= m || tz < 0 || tz >= l) continue; if(g[tz][tx][ty]) { g[tz][tx][ty] = 0; Q.push(node(tx,ty,tz)); cnt++; } } } return;}int main(){ while(~scanf("%d%d%d%d",&n,&m,&l,&t)){ for(int k=0;k<l;k++) for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&g[k][i][j]); int ans = 0; for(int k=0;k<l;k++) for(int i=0;i<n;i++) for(int j=0;j<m;j++){ if(g[k][i][j]){ cnt = 1; bfs(k,i,j); if(cnt >= t) ans += cnt; } } printf("%d\n",ans); } return 0;}
0 0
- GPLT L3-004. 肿瘤诊断【三维bfs求连通块】
- PAT天梯赛练习题——L3-004. 肿瘤诊断(三维连通块并查集)
- PAT L3-004. 肿瘤诊断 (BFS)
- 肿瘤诊断(三维BFS)
- 团体程序设计天梯赛-练习集-L3-004. 肿瘤诊断(三维bfs)
- L3-004. 肿瘤诊断
- L3-004. 肿瘤诊断
- L3-004. 肿瘤诊断
- L3-004. 肿瘤诊断
- L3-004. 肿瘤诊断
- 天梯赛 L3-004. 肿瘤诊断(BFS)
- L3-004. 肿瘤诊断-PAT团体程序设计天梯赛GPLT(广度优先搜索)
- 2016年团体程序设计天梯赛-模拟赛 L3-1. 肿瘤诊断 (三维 BFS)
- C4top-肿瘤诊断(BFS-三维搜索)
- 肿瘤诊断 L3-004
- L3-004. 肿瘤诊断 天梯赛模拟题
- 团体程序设计天梯赛-L3-004. 肿瘤诊断
- 【题解】PAT.团体程序设计天梯赛.L3-004.肿瘤诊断
- Kafka与UnknownHostException
- C语言中的指针常量与常量指针
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- ESP8266--学习笔记(转载资料一)
- c++ 知识汇总
- GPLT L3-004. 肿瘤诊断【三维bfs求连通块】
- MongoDB相关
- swift数据持久化之属性列表,解决plist写入失败的问题
- 一、开始学习c++
- hdu 1480 钥匙计数之二
- linux 达人养成计划 II笔记
- java日志文件log4j.properties配置详解
- CSShack 布局
- 编译 OpenCV 避免下载 linux-64-opencv-2.4.11-nppy27_0.tar.bz2