Run ID:101811
提交时间:2024-12-18 21:58:35
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; // 读取导弹的数量 vector<int> heights(n); // 存储导弹高度的向量 for (int i = 0; i < n; ++i) { cin >> heights[i]; // 读取每颗导弹的高度 } vector<int> systems; // 存储每个系统拦截导弹的最大高度 int maxHeight = 0; // 当前系统的最大高度 for (int height : heights) { if (height > maxHeight) { // 如果当前导弹高度大于所有系统的最大高度,新增一个系统 systems.push_back(height); maxHeight = height; // 更新最大高度 } else { // 否则,找到第一个高度大于等于当前导弹高度的系统进行拦截 auto it = upper_bound(systems.begin(), systems.end(), height); maxHeight = *it; // 更新最大高度为拦截该导弹的系统高度 } } cout << systems.size() << endl; // 输出系统的数量 return 0; }