当前位置: 首页 > news >正文

9.15 滴滴笔试

T1(二分)

#include <bits/stdc++.h>#define endl '\n'using namespace std;typedef long long LL;const int N = 1e5 + 10;int n, k;
int a[N];bool check(int mid) {int rec = 1e9, cnt = 1;for(int i = 0; i < n; i ++) {int j = i;while(j < n && a[j] - a[i] < mid) j ++ ;if(j < n) rec = min(rec, a[j] - a[i]), cnt ++;i = j - 1;}return cnt >= k && rec >= mid;
}void solve() {cin >> n >> k;for(int i = 0; i < n; i ++) cin >> a[i];int l = 1, r = 1e6 + 10;while(l < r) {int mid = l + r + 1 >> 1;if(check(mid)) l = mid;else r = mid - 1;}cout << r << endl;
}int main() {cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);int T = 1;
//	cin >> T;while(T --) {solve();}return 0;
}

T2(01BFS)

#include <bits/stdc++.h>#define x first
#define y second#define endl '\n'using namespace std;typedef long long LL;
typedef pair<int, int> PII;const int N = 1e5 + 10;int n, m;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};void solve() {cin >> n >> m;vector<vector<int>> g(n, vector<int> (m));vector<vector<int>> dist(n, vector<int> (m, 1e9));for(int i = 0; i < n; i ++) {for(int j = 0; j < m; j ++) {cin >> g[i][j];}}deque<PII> q;q.push_back({0, 0});dist[0][0] = g[0][0];while(q.size()) {auto t = q.front(); q.pop_front();int x = t.x, y = t.y;for(int i = 0; i < 4; i ++) {int a = x + dx[i], b = y + dy[i];if(a >= 0 && a < n && b >= 0 && b < m) {if(dist[a][b] > dist[x][y] + g[a][b]) {dist[a][b] = dist[x][y] + g[a][b];if(g[a][b] == 1) {q.push_back({a, b});} else {q.push_front({a, b});}}}}}cout << dist[n - 1][m - 1] << endl;
}int main() {cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);int T = 1;
//	cin >> T;while(T --) {solve();}return 0;
}
http://www.lryc.cn/news/167295.html

相关文章:

  • 有趣的设计模式——适配器模式让两脚插头也能使用三孔插板
  • 2.10 PE结构:重建重定位表结构
  • 关于content-type的理解
  • <图像处理> 空间滤波基础二
  • Java中的队列Queue
  • 机器学习技术(十)——决策树算法实操,基于运营商过往数据对用户离网情况进行预测
  • 大数据之-kafka学习笔记
  • 虚幻动画系统概述
  • 什么是集成测试?集成测试方法有哪些?
  • elementUI中的el-form常用校验规则
  • 蓝桥杯打卡Day9
  • C# 辗转相除法求最大公约数
  • 腾讯mini项目-【指标监控服务重构】2023-08-03
  • redis缓存穿透、击穿、雪崩介绍
  • Redis 基础总结
  • 基于nginx的tomcat负载均衡和集群(超简单)
  • ESIM实战文本匹配
  • 基于虚拟仿真技术的汽车燃油泵控制
  • angular:HtmlElement的子节点有Shadow dom时奇怪的现象
  • 栈与队列--删除字符串中的所有相邻重复项
  • 使用SSH地址拉取远程仓库代码报下面的错误
  • easycms v5.5 分析 | Bugku S3 AWD排位赛
  • 成都营运《乡村振兴战略下传统村落文化旅游设计》许少辉八一著作
  • 创邻科技Galaxybase助力SPG推动知识图谱应用落地
  • 《TCP/IP网络编程》阅读笔记--域名及网络地址
  • 我的C#基础
  • 【UnityShaderLab实现“Billboard“始终面向相机_播放序列图的效果_案例分享(内附源码)】
  • Ceph入门到精通-S3 基准测试工具warp使用入门
  • Docker--未完结
  • string的使用和模拟实现