当前位置:网站首页>笔试题大疆08.07
笔试题大疆08.07
2022-08-11 07:59:00 【seize the chance2022】
题目如下:
输入输出的测试用例如下所示:
测试用例如下:
6 6 2 3 3
37 37 39 41 13 205
37 41 41 203 39 243
37 41 40 131 40 41
91 41 39 198 41 9
189 41 39 40 40 38
37 124 38 167 41 41
这道题采用BFS解决问题,这道题和力扣上岛屿问题很类似。
代码如下:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
void bfs(vector<vector<int>>& grid, vector<vector<bool>>& box, int& nowNum, int nowx, int nowy, int T)
{
vector<int> x = {
0,0,1,-1 };
vector<int> y = {
-1,1,0,0 };
int target = grid[nowx][nowy];
queue<pair<int, int>> pos;
pos.push(make_pair(nowx, nowy));
while (!pos.empty()) {
for (int i = 0; i < 4; i++) {
int tempx = pos.front().first + x[i];
int tempy = pos.front().second + y[i];
if (tempx >= 0 && tempy >= 0 && tempx < grid.size() && tempy < grid[0].size() && !box[tempx][tempy]
&& grid[tempx][tempy] >= target - T + 1 && grid[tempx][tempy] <= target + T - 1) {
pos.push(make_pair(tempx, tempy));
box[tempx][tempy] = true;
nowNum++;
}
}
pos.pop();
}
}
int main()
{
int n, m, x, y, t;
int retSum = 0;
cin >> n >> m >> x >> y >> t;
vector<vector<int>> vec(n, vector<int>(m, 0));
vector<vector<bool>> box(n, vector<bool>(m, false));
for (size_t i = 0; i < n; ++i) {
for (size_t j = 0; j < m; ++j) {
cin >> vec[i][j];
}
}
bfs(vec, box, retSum, y, x, t);
cout << retSum << endl;
system("Pause");
return 0;
}
运行结果如下:
边栏推荐
- 项目1-PM2.5预测
- magical_spider远程采集方案
- My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful
- The growth path of a 40W test engineer with an annual salary, which stage are you in?
- 零基础SQL教程: 主键、外键和索引 04
- go 操作MySQL之mysql包
- 1071 小赌怡情 (15 分)
- 记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.
- 欧拉函数(用欧拉筛法求欧拉函数)
- 借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
猜你喜欢
随机推荐
Serverless + domain name can also build a personal blog? Really, and soon
oracle19c不支持实时同步参数,请教一下大佬们有什么好的解决办法吗?
1071 Small Gamble (15 points)
Do you know the basic process and use case design method of interface testing?
XXL-JOB 分布式任务调度中心搭建
1036 Programming with Obama (15 points)
klayout--导出版图为gds文件
go sqlx 包
go 操作MySQL之mysql包
RestTemplate工具类
Two startup methods and differences of Service
【LeetCode】链表题解汇总
1.2-误差来源
查询跟踪快递单号物流,智能分析物流中转有延误的单号
2022 China Soft Drink Market Insights
JRS303-Data Verification
机器学习(一)数据的预处理
Creo9.0 特征的成组
3.1-Classification-probabilistic generative model
为什么会没有内存了呢