Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
193911 | luckypet | 抄近路 | C++ | 解答错误 | 55 | 0 MS | 252 KB | 1278 | 2025-05-27 15:15:32 |
#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; struct Point { int x, y; bool operator<(const Point& other) const { return x < other.x || (x == other.x && y < other.y); } }; int main() { int N, M, K; cin >> N >> M >> K; vector<Point> parks(K); for (int i = 0; i < K; ++i) { cin >> parks[i].x >> parks[i].y; } // 转换为对角线端点并排序 vector<Point> diagonals; for (auto& p : parks) { diagonals.push_back({p.x, p.y}); } sort(diagonals.begin(), diagonals.end()); // 动态规划计算最长非降序子序列 vector<int> tails; for (auto& d : diagonals) { int y = d.y; auto it = lower_bound(tails.begin(), tails.end(), y); if (it == tails.end()) { tails.push_back(y); } else { *it = y; } } int max_diagonals = tails.size(); double diagonal_distance = max_diagonals * 100 * sqrt(2); double straight_distance = (N + M - 2 * max_diagonals) * 100.0; double total = diagonal_distance + straight_distance; cout << static_cast<int>(round(total)) << endl; return 0; }