PAT A1091 Acute Stroke

  • 题不太好读,比较吓人的样子,然而方法就是存入三维数组,然后对每一个没有访问过的点1做bfs(扫描上下前后左右的1入队),如果本次bfs的cnt值>=T,则累加入结果
  • 注意想好visited置位和cnt++的时机,否则就会多算或者少算,调试也比较麻烦
  • 把visited也弄成三维的,q里面push三维坐标的结构体应该能节省一些脑细胞
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>using namespace std;#define MAXM 1286
#define MAXN 128
#define MAXL 60
#define INF 999999999int G[MAXL][MAXM][MAXN];
bool visited[MAXL * MAXM * MAXN] = {false};
queue<int> q;
int Xoffset[] = {0,0,0,0,1,-1};
int Yoffset[] = {0,0,1,-1,0,0};
int Zoffset[] = {1,-1,0,0,0,0};
int total = 0;#define DEBUG 1int main(){#ifdef DEBUGfreopen("1.txt","r",stdin);
#endifint M,N,L,T;cin >> M >> N >> L >> T;fill(G[0][0],G[0][0] + MAXL * MAXM * MAXN,INF);fill(visited,visited + MAXL * MAXM * MAXN,false);for(int i = 0;i < L;i ++){for(int j = 0;j < M;j ++){for(int k = 0;k < N;k ++){scanf("%d",&G[i][j][k]);}}}for(int i = 0;i < L;i ++){for(int j = 0;j < M;j ++){for(int k = 0;k < N;k ++){if(G[i][j][k] != 1) continue;int start = i * MAXM * MAXN + j * MAXN + k;if(visited[start]) continue;int cnt = 0;q.push(start);visited[start] = true;while(!q.empty()){int now = q.front();q.pop();cnt ++;int nowx = now % MAXN;int nowy = (now % (MAXM * MAXN)) / MAXN;int nowz = now / (MAXM * MAXN);for(int v = 0;v < 6;v ++){int testx = Xoffset[v] + nowx;if(testx < 0 || testx >= N) continue;int testy = Yoffset[v] + nowy;if(testy < 0 || testy >= M) continue;int testz = Zoffset[v] + nowz;if(testz < 0 || testz >= L) continue;int pos = testz * MAXM * MAXN + testy * MAXN + testx;if(!visited[pos] && G[testz][testy][testx] == 1){q.push(pos);visited[pos] = true;}}}if(cnt >= T) total += cnt;}}}cout << total;return 0;
}

PAT A1091 Acute Stroke ——帘卷西风,人比黄花瘦相关推荐

  1. PAT A1091 Acute Stroke

    1091 Acute Stroke (30分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

  2. 1091. Acute Stroke (30)-PAT甲级真题(广度优先搜索)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  3. 1091 Acute Stroke (PAT甲级)

    这道题用dfs做的话,因为递归太多层,堆栈溢出,有两个测试点过不了:所以用bfs. 根据他人代码修改后的结果: #include <cstdio> #include <vector& ...

  4. PAT甲级 1091 Acute Stroke(30) (Flood Fill)

    题目 One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the ...

  5. 1091 Acute Stroke (30)(30 分)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  6. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  7. pat1091. Acute Stroke (30)

    1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...

  8. 【PTA-A】1091 Acute Stroke (30 分)(BFS、队列)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  9. 「1091」Acute Stroke

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

最新文章

  1. 2022-2028年中国电容器用薄膜行业市场研究分析及投资前景展望报告
  2. boost::mpl模块实现unpack_args相关的测试程序
  3. phpgif图片包_php生成动态验证码gif图片
  4. mvc调用mysql存储过程_使用.NET MVC +EF调用oracle的存储过程
  5. 数据结构之队列的特别实现
  6. 终止运行线程的注意事项
  7. 【转】关于OnPaint的工作机制
  8. 完整详尽的解决MySql:Could not create connection to database server
  9. 易语言教程_v20200926
  10. struts2拦截器定义
  11. 《非暴力沟通》- 使人情意相通的沟通方式
  12. 稳定的IP地址查询接口
  13. 如何制作六一儿童节答题测试H5页面?
  14. 计算机逻辑函数,计算机智能化简多变量逻辑函数的算法分析
  15. Unity-tweak-tool插件
  16. Spring Cloud之Hystrix服务容错
  17. Windows如何远程连接服务器?Linux服务器如何远程登录?远程连接服务器命令
  18. vue RSA加密算法(jsencrypt)的使用
  19. 如何一键制作css精灵图?
  20. 软件测试---测试技术(2)

热门文章

  1. java获取时间00:00:00和23:59:59
  2. java实践项目_20个Java练手项目,实践才是硬道理
  3. (五)以太坊——委托投票智能合约
  4. C语言程序设计(谭浩强第五版)——习题
  5. 《HTTP权威指南》第一章学习总结
  6. C++ 文件读写实战——2进制文件查看器(16进制显示)
  7. 第五届“泰迪杯“技能赛赛题讲解直播来啦
  8. 网络是怎样连接的--TCP大致控制流程
  9. android自动关机代码
  10. 《转》批处理经典入门教程!(从不懂到高手)