当前位置:网站首页>笔试题大疆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;
}
运行结果如下:
边栏推荐
- 查询跟踪快递单号物流,智能分析物流中转有延误的单号
- 1036 Programming with Obama (15 points)
- Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
- 1003 我要通过 (20 分)
- 抽象类和接口
- tf.cast(), reduce_min(), reduce_max()
- 3.1-分类-概率生成模型
- 借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
- excel 透视表 值显示内容 不显示计数
- RestTemplate工具类
猜你喜欢
The growth path of a 40W test engineer with an annual salary, which stage are you in?
2022 China Soft Drink Market Insights
IQUNIX A80 exploring TTC金粉 初体验
1036 Programming with Obama (15 points)
[C语言] sscanf如何实现sscanf_s?
3.1-Classification-probabilistic generative model
1096 大美数 (15 分)
通过记账,了解当月收支情况
【LeetCode】链表题解汇总
基于微信小程序的租房小程序
随机推荐
1091 N-Defensive Number (15 points)
jenkins简单使用
4.1-支持向量机
JRS303-数据校验
Dynamic Agent Learning
IQUNIX A80 exploring TTC金粉 初体验
Do you know the basic process and use case design method of interface testing?
进阶-指针
JRS303-Data Verification
1081 检查密码 (15 分)
matplotlib
机器学习(二)线性回归
零基础SQL教程: 基础查询 05
1002 写出这个数 (20 分)
Serverless + domain name can also build a personal blog? Really, and soon
欧拉函数(用欧拉筛法求欧拉函数)
Evolution and New Choice of Streaming Structured Data Computing Language
抽象类和接口
tf.cast(), reduce_min(), reduce_max()
Machine Learning Summary (2)