大疆笔试 大疆笔试题 0818
笔试时间:2024年08月18日
历史笔试传送门:2023秋招笔试合集
第一题
题目
小C开发了一种新型的无人机机场系统。每个机场能够容纳最多15架无人机,并且每个机场都有唯一的编号。无人机每次起飞或降落,调度中心都会记录对应的机场编号。在某个特定时刻,所有的机场都是空的。从那个时刻开始,调度中心记录了一段时间内所有起飞和降落无人机的机场编号。现在小C想知道在这段时间后,每个机场的无人机数量分布情况,即存放飞机数量为1到15的机场各有多少台?机场编号最大为2^20,飞机起飞降落架次最大为1.8*10^6。
输入描述
共4行。
第1行为降落至机场的飞机架次
第2行为按顺序记景有飞机降落的机场编号
第3行为从机场起飞的飞机架次
第4行为按顶序记录有飞机起飞的机场编号
输出描述
依次输出存放飞机数量为1到15的机场各有多少台,中间以空格隔开。
样例输入
15
6 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
5
1 2 3 4 5
样例输出
0 5 0 0 0 0 0 0 0 0 0 0 0 0 0
参考题解
哈希。
C++:[此代码未进行大量数据的测试,仅供参考]
#include <iostream>
#include <unordered_map>
#include <vector>
int main() {
int landCnt;
std::cin >> landCnt;
std::unordered_map<int, int> apMap;
for (int i = 0; i < landCnt; ++i) {
int apId;
std::cin >> apId;
apMap[apId]++;
}
int takeoff_count;
std::cin >> takeoff_count;
for (int i = 0; i < takeoff_count; ++i) {
int apId;
std::cin >> apId;
apMap[apId]--;
}
std::vector<int> count(16, 0);
for (const auto& entry : apMap) {
int drones = entry.second;
if (drones > 0 && drones <= 15) {
count[drones]++;
}
}
for (int i = 1; i <= 15; ++i) {
if (i > 1) std::cout << " ";
std::cout << count[i];
}
std::cout << std::endl;
return 0;
}
Java:[此代码未进行大量数据的测试,仅供参考]
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class DroneCounter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int landCnt = scanner.nextInt();
Map<Integer, Integer> apMap = new HashMap<>();
for (int i = 0; i < landCnt; i++) {
int apId = scanner.nextInt();
apMap.put(apId, apMap.getOrDefault(apId, 0) + 1);
}
int takeoff_count = scanner.nextInt();
for (int i = 0; i < takeoff_count; i++) {
int apId = scanner.nextInt();
apMap.put(apId, apMap.getOrDefault(apId, 0) - 1);
}
int[] count = new int[16];
for (Map.Entry<Integer, Integer> entry : apMap.entrySet()) {
int drones = entry.getValue();
if (drones >
剩余60%内容,订阅专栏后可继续查看/也可单篇购买
2024 BAT笔试合集 文章被收录于专栏
持续收录字节、腾讯、阿里、美团、美团、拼多多、华为等笔试题解,包含python、C++、Java多种语言版本,持续更新中。
查看11道真题和解析