网站首页鲁大师,深圳网站 建设,做网站网站建设,十堰优化网站公司网址如下#xff1a;
Printer Queue - UVA 12100 - Virtual Judge (vjudge.net)
#xff08;第三方网站#xff09; 很简单的一道队列题#xff0c;模拟一下就可以了
但是我觉得我可以优化一下算法
然而要上高数了 代码如下#xff1a;
#includequeue
#inclu…网址如下
Printer Queue - UVA 12100 - Virtual Judge (vjudge.net)
第三方网站 很简单的一道队列题模拟一下就可以了
但是我觉得我可以优化一下算法
然而要上高数了 代码如下
#includequeue
#includecstdio
#includecstring
using namespace std;
bool is_judge(int loc);
int q[10];int main(void)
{int T, m, n;scanf(%d, T);for(int kase 0; kase T; kase){//输入memset(q, 0, sizeof(q));queueint n_queue;scanf(%d%d, n, m);for(int i 0; i n; i){int tmp; scanf(%d, tmp);n_queue.push(tmp); q[tmp];}//开始计算时间int time{};while(true){int top n_queue.front();if(is_judge(top)) n_queue.push(top), n_queue.pop(), m m ? m - 1 : n_queue.size() - 1;else{n_queue.pop(), time, q[top]--;if(m) m--;else break;}}printf(%d\n, time);}return 0;
}
bool is_judge(int loc)
{for(int i loc 1; i 10; i)if(q[i]) return true;return false;
}