暴力求解???
代码如下:
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
int job[10];
int n, time = 0, id;
queue<int>s;
//判断是否在存在优先级更高的元素;
bool check(int now_id) {
bool sign = true;
for (int j = now_id + 1; j < n; j++) {
if (job[j] != 0)
return sign = false;
else
return sign;
}
}
//从首位一直计算到id;
void to_id() {
int kase = 0, m;
while (kase++ < id) {
m = s.front();
s.pop();
if (check(m)) {
time++;
job[m]--;
}
else {
s.push(m);
}
}
}
//递归调用,计算时间的(仅记录思路用,请忽略)
/*
void cal_time(int now_id) {
int kase = now_id, m;
if (check(kase)) {
m = s.front();
kase = 0;
cal_time(kase++);
}
}
*/
int main() {
cin >> n;
int t = 0, k, id;
while (t++ < n) {
cin >> k;
s.push(k);
job[k]++;
}
cin >> id;
int m;
//单独判断;
while (1) {
m = s.front();
s.pop();
if (check(m)) {
time++;
break;
}
else {
s.push(m);
to_id();
}
}
cout << time << endl;
return 0;
}