提交时间:2026-04-18 15:44:14
运行 ID: 436801
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; // 输入导弹数量 cin >> n; vector<int> missiles(n); for (int i = 0; i < n; ++i) { cin >> missiles[i]; } // 存储每套系统当前能拦截的最大高度(最后一发的高度) vector<int> systems; for (int h : missiles) { bool found = false; // 贪心:找第一个 高度 >= 当前导弹高度 的系统 // 这样能让低高度系统留给更小的导弹,最优解 for (int &s : systems) { if (s >= h) { s = h; // 更新这套系统的最大拦截高度 found = true; break; } } // 没有找到可用系统,新增一套 if (!found) { systems.push_back(h); } } // 系统数量就是答案 cout << systems.size() << endl; return 0; }