我是靠谱客的博主 舒服草莓,最近开发中收集的这篇文章主要介绍Autox笔试笔记(键盘距离&追车问题),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

追车问题:

//追车问题
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// Complete the MaximumArriveAtSameTime function below.
class Solver{
public:
static bool compare(const pair<double, double>& left, const pair<double, double>& right) {
return left.first > right.first;
}
int MaximumArriveAtSameTime(vector<double>& speed, vector<double>& location, double destination) {
int n = location.size();
//计算每个车到达终点所需时间
vector<double> times(n, 0);
for (int i = 0; i < n; i++) {
double time = (destination - location[i]) / speed[i];
times[i] = time;
}
//根据位置对时间进行排序
vector<pair<double, double>> loc_time(n);
for (int i = 0; i < n; i++) {
loc_time[i].first = location[i];
loc_time[i].second = times[i];
}
sort(loc_time.begin(), loc_time.end(), compare);
double maxTime = 0;
int maxNum = 0;
int rst = 1;
for (int i = 0; i < n; i++) {
double curTime = loc_time[i].second;
if (curTime > maxTime) {
maxNum = 1;
maxTime = curTime;
} else {
maxNum++;
}
rst = max(maxNum, rst);
}
return rst;
}
};
//
Non-editable part
int main()
{
int speed_count;
cin >> speed_count;
vector<double> speed(speed_count);
for (int i = 0; i < speed_count; i++) {
double speed_item;
cin >> speed[i];
}
int location_count = speed_count;
vector<double> location(location_count);
for (int i = 0; i < location_count; i++) {
double location_item;
cin >> location[i];
}
double destination;
cin>>destination;
Solver solver;
int res = solver.MaximumArriveAtSameTime(speed, location, destination);
std::cout << res << "n";
return 0;
}

键盘数字问题:

#include <iostream>
#include <vector>
#include <memory>
#include <map>
#include <cmath>
#include <algorithm>
#include <limits.h>
#include <unordered_map>
// using namespace std;
#include <bits/stdc++.h>
using namespace std;
int entryTime(string str, string keypad) {
int rst = 0;
int n = str.size();
//记录每个坐标
vector<vector<int>> locate(n, vector<int>(2, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 9; j++) {
if (str[i] == keypad[j]) {
locate[i][0] = j / 3;
locate[i][1] = j - locate[i][0] * 3;
}
}
}
//计算每次变化情况
vector<vector<int>> delta(n - 1, vector<int>(2, 0));
for (int i = 0; i < n - 1; i++) {
delta[i][0] = locate[i + 1][0] - locate[i][0];
delta[i][1] = locate[i + 1][1] - locate[i][1];
}
for (int i = 0; i < n - 1; i++) {
int dist = sqrt(delta[i][0] * delta[i][0] + delta[i][1] * delta[i][1]);
if (dist == 1) rst += 1;
else if (dist == 2) rst += 2;
}
return rst;
}

最后

以上就是舒服草莓为你收集整理的Autox笔试笔记(键盘距离&追车问题)的全部内容,希望文章能够帮你解决Autox笔试笔记(键盘距离&追车问题)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部