本文主要是介绍12100 - Printer Queue (UVA),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接如下:
Online Judge
我的代码如下:
#include <cstdio>
#include <queue>
#include <utility>
#include <algorithm>
// #define debugstruct job{int priority;bool flag = false;job(int _pri): priority(_pri){}
};
int kase, n, m, k, pivotPriority, cnt;
std::queue<job> q;
int nbr[10];int main(){#ifdef debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifscanf("%d", &kase);while (kase--){scanf("%d %d", &n, &m);std::queue<job> empty;std::swap(q, empty);std::fill(nbr, nbr + 10, 0);for (int i = 0; i < n; ++i){scanf("%d", &k);nbr[k]++;q.push(job(k));if (i == m){pivotPriority = k;q.back().flag = true;}}cnt = 0;for (int i = 9; i >= pivotPriority; --i){while (nbr[i]){if (q.front().priority == i){cnt++;if (q.front().flag){printf("%d\n", cnt);i = -1;break;}q.pop();nbr[i]--;} else{q.push(q.front());q.pop();}}}}#ifdef debugfclose(stdin);fclose(stdout);#endifreturn 0;
}
这篇关于12100 - Printer Queue (UVA)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!