This commit is contained in:
2026-07-28 00:33:27 +08:00
parent 2b6dc69bde
commit 8bc1b22a1c
14 changed files with 529 additions and 124 deletions
+40
View File
@@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int shortest_fall_time(const int length, vector<int> ant_pos) {
sort(ant_pos.begin(), ant_pos.end(),
[length](const int pos1, const int pos2) {
return abs(pos1 - length / 2) < abs(pos2 - length / 2); // 到中点距离最短者
});
return min(ant_pos[0], length - ant_pos[0]);
}
int longest_fall_time(const int length, vector<int> ant_pos) {
sort(ant_pos.begin(), ant_pos.end(),
[length](const int pos1, const int pos2) {
return abs(pos1 - length / 2) > abs(pos2 - length / 2); // 到中点距离最长者
});
return max(ant_pos[0], length - ant_pos[0]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int group_count;
cin >> group_count;
for (int _ = 0; _ < group_count; _++) {
int length, ant_count;
cin >> length >> ant_count;
vector<int> ant_pos(ant_count);
for (int i = 0; i < ant_count; i++) {
cin >> ant_pos[i];
}
cout << shortest_fall_time(length, ant_pos) << " " << longest_fall_time(length, ant_pos) << endl;
}
return 0;
}