Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
193991 | luckypet | 木板游戏 | C++ | 解答错误 | 0 | 0 MS | 256 KB | 1036 | 2025-05-29 14:24:59 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Board { int l, r; }; bool compare(const Board& a, const Board& b) { if (a.l == b.l) return a.r > b.r; return a.l < b.l; } int main() { int n; cin >> n; vector<Board> boards(n); for (int i = 0; i < n; i++) { cin >> boards[i].l >> boards[i].r; } // 按照左端点升序排序,左端点相同则按右端点降序排序 sort(boards.begin(), boards.end(), compare); // 维护一个右端点的单调递增序列 vector<int> dp; for (const auto& board : boards) { // 找到第一个大于board.r的位置 auto it = upper_bound(dp.begin(), dp.end(), board.r); if (it == dp.end()) { // 如果都比它小,直接添加 dp.push_back(board.r); } else { // 替换第一个大于它的元素 *it = board.r; } } cout << dp.size() << endl; return 0; }