Files
python/TangDou/XiTi/1378.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

49 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int main() {
//m人员数,n:共执行几轮
int n, m;
cin >> n >> m;
queue<int> qPerson; //人员队列
queue<int> qCmd; //命令队列
//构建人员原始队列
for (int i = 1; i <= m; ++i) {
qPerson.push(i);
}
//构建出队出列的规则队列
for (int i = 0; i < n; ++i) {
int c;
cin >> c;
qCmd.push(c);
}
//开始模拟
for (int i = 0; i < n; ++i) { //要进行n轮次
//如果人员都没有了,还有剩余指令,那么无法执行
if (qPerson.empty()) break;
int p = qCmd.front();
//前面p-1个人员排到最后
for (int j = 1; j < p; ++j) {
int pi = qPerson.front();
qPerson.pop();
qPerson.push(pi);
}
//出列第p个人员
qPerson.pop();
//执行完一条命令
qCmd.pop();
}
//输出最终的队列中还剩下的人员编号
if (qPerson.empty()) cout << -1 << endl;
else {
while (!qPerson.empty()) {
cout << qPerson.front() << " ";
qPerson.pop();
}
cout << endl;
}
return 0;
}