博客
关于我
习题5-7 打印队列(Printer Queue,ACM/ICPC NWERC 2006,UVa12100)
阅读量:303 次
发布时间:2019-03-03

本文共 699 字,大约阅读时间需要 2 分钟。

原题链接:

分类:<vector>
备注:水题

代码如下:

#include
#include
using namespace std;int main(void){ int T; scanf("%d", &T); while (T--) { int n, pos; vector
q; scanf("%d%d", &n, &pos); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); q.push_back(x); } int cnt = 0; while (1) { cnt++; while (1) { int head = q[0], flag = 1; for (int i = 1; i < q.size(); i++) if (q[i] > head) { q.push_back(head); q.erase(q.begin()); if (pos == 0)pos = q.size() - 1; else pos--; flag = 0; break; } if (flag) { q.erase(q.begin()); pos--; break; } } if (pos == -1)break; } printf("%d\n", cnt); } return 0;}

转载地址:http://odel.baihongyu.com/

你可能感兴趣的文章
mysql 转义字符用法_MySql 转义字符的使用说明
查看>>
mysql 输入密码秒退
查看>>
mysql 递归查找父节点_MySQL递归查询树状表的子节点、父节点具体实现
查看>>
mysql 通过查看mysql 配置参数、状态来优化你的mysql
查看>>
mysql 里对root及普通用户赋权及更改密码的一些命令
查看>>
Mysql 重置自增列的开始序号
查看>>
mysql 锁机制 mvcc_Mysql性能优化-事务、锁和MVCC
查看>>
MySQL 错误
查看>>
mysql 随机数 rand使用
查看>>
MySQL 面试题汇总
查看>>
MySQL 面试,必须掌握的 8 大核心点
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>
MySQL-Buffer的应用
查看>>
mysql-cluster 安装篇(1)---简介
查看>>