You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#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;
|
|
|
|
|
}
|