PAT A1091 Acute Stroke ——帘卷西风,人比黄花瘦
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 ——帘卷西风,人比黄花瘦相关推荐
- PAT A1091 Acute Stroke
1091 Acute Stroke (30分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
- 1091. Acute Stroke (30)-PAT甲级真题(广度优先搜索)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 1091 Acute Stroke (PAT甲级)
这道题用dfs做的话,因为递归太多层,堆栈溢出,有两个测试点过不了:所以用bfs. 根据他人代码修改后的结果: #include <cstdio> #include <vector& ...
- PAT甲级 1091 Acute Stroke(30) (Flood Fill)
题目 One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the ...
- 1091 Acute Stroke (30)(30 分)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- pat1091. Acute Stroke (30)
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- 【PTA-A】1091 Acute Stroke (30 分)(BFS、队列)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 「1091」Acute Stroke
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
最新文章
- 2022-2028年中国电容器用薄膜行业市场研究分析及投资前景展望报告
- boost::mpl模块实现unpack_args相关的测试程序
- phpgif图片包_php生成动态验证码gif图片
- mvc调用mysql存储过程_使用.NET MVC +EF调用oracle的存储过程
- 数据结构之队列的特别实现
- 终止运行线程的注意事项
- 【转】关于OnPaint的工作机制
- 完整详尽的解决MySql:Could not create connection to database server
- 易语言教程_v20200926
- struts2拦截器定义
- 《非暴力沟通》- 使人情意相通的沟通方式
- 稳定的IP地址查询接口
- 如何制作六一儿童节答题测试H5页面?
- 计算机逻辑函数,计算机智能化简多变量逻辑函数的算法分析
- Unity-tweak-tool插件
- Spring Cloud之Hystrix服务容错
- Windows如何远程连接服务器?Linux服务器如何远程登录?远程连接服务器命令
- vue RSA加密算法(jsencrypt)的使用
- 如何一键制作css精灵图?
- 软件测试---测试技术(2)