```cpp #include <iostream> #include <vector> #include <queue> using namespace std; struct Monster { int health; int index; bool operator<(const Monster& other) const { return health < other.health; } }; int main() { int n, k; cin >> n >> k; priority_queue<Monster> pq; for (int i = 0; i < n; ++i) { int health; cin >> health; pq.push({health, i + 1}); } vector<int> deathOrder; while (!pq.empty()) { Monster current = pq.top(); pq.pop(); deathOrder.push_back(current.index); current.health -= k; if (current.health > 0) { pq.push(current); } } for (int i = 0; i < n; ++i) { cout << deathOrder[i] << " "; } return 0; } // 逻辑点: // 1. 使用优先队列(堆)来维护当前生命值最高的怪物,以便每次选择生命值最高的怪物进行攻击。 // 2. 将怪物结构体按生命值降序排列,并记录怪物的初始编号,以便输出最终的死亡顺序。 // 3. 循环处理每个怪物,每次造成伤害后检查生命值是否大于0,若是则重新加入优先队列,直到所有怪物死亡。 ``` [2025-01-06 19:43:03 | AI写代码神器 | 730点数解答]