Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
101811 | 彭士宝 | 导弹拦截问题 | C++ | Wrong Answer | 1 MS | 276 KB | 1081 | 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; }
------Input------
123 256 369 213 456 956 23 698 1236 321 500 666
------Answer-----
6
------Your output-----
8