当前位置:网站首页>笔试题大疆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;
}
运行结果如下:
边栏推荐
- jenkins简单使用
- Redis source code-String: Redis String command, Redis String storage principle, three encoding types of Redis string, Redis String SDS source code analysis, Redis String application scenarios
- Two startup methods and differences of Service
- Conditional statements in TF; where()
- 1002 写出这个数 (20 分)
- 链式编程注解
- 选择收银系统主要看哪些方面?
- 剑指offer专项突击版第26天
- JRS303-数据校验
- 1101 How many times B is A (15 points)
猜你喜欢
1106 2019 Sequence (15 points)
1061 判断题 (15 分)
机器学习(一)数据的预处理
Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
无服务器+域名也能搭建个人博客?真的,而且很快
Redis source code-String: Redis String command, Redis String storage principle, three encoding types of Redis string, Redis String SDS source code analysis, Redis String application scenarios
TF中使用softmax函数;
1056 组合数的和 (15 分)
囍楽cloud task source code
3.2-分类-Logistic回归
随机推荐
【LeetCode】Summary of linked list problems
1056 Sum of Combinations (15 points)
oracle数据库中列转行,列会有变化
2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪
4.1 - Support Vector Machines
1.2-误差来源
JRS303-Data Verification
小目标检测3_注意力机制_Self-Attention
Four states of Activity
oracle19c不支持实时同步参数,请教一下大佬们有什么好的解决办法吗?
美术2.4 UV原理基础
装饰器模式:Swift 实现
2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号 0 的弹簧处。若小球在编号为 i 的弹
记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.
机器学习(二)线性回归
tf.reduce_mean() and tf.reduce_sum()
【Day_13 0509】▲跳石板
The softmax function is used in TF;
IQUNIX A80 exploring TTC金粉 初体验
1091 N-自守数 (15 分)