Codeforces 665B - Shopping
2016-04-27 23:57
399 查看
这道题太直白了,直接用双端队列就解决了。意思是,n个人,每个人要取m个东西,当一个人拿了一件东西后,这件东西就会放在队列最前面,问总共要花的时间。
#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; typedef deque<int>::iterator iterator_t; int main() { deque<int> que; int n, m, k; scanf("%d%d%d", &n, &m, &k); int tmp; for (int i = 0; i != k; ++i) { scanf("%d", &tmp); que.push_back(tmp); } int tot_time = 0; int val; for (int i = 0; i != n; ++i) { for (int j = 0; j != m; ++j) { scanf("%d", &val); for (iterator_t it = que.begin(); it != que.end(); ++it) { tot_time++; if (*it == val) { //printf("first %d\n", que.size()); que.erase(it); que.push_front(val); // for (int i = 0; i < que.size(); ++i) //{ // printf("%d ", que[i]); //} //puts(""); break; } } } } printf("%d\n", tot_time); return 0; }
相关文章推荐
- Linux c 数组大小的限制
- 关于opencv从图中画圈的思考
- 20135337——实践一:Linux基础配置
- Nginx 配置示例
- CentOS安装openoffice的方法
- SetSockOpt 详解
- Linux的一些总结
- 第二次作业(2.linux下的小程序)
- Properties Editor 是一款properties文件编辑器。
- 'No package nginx available' error CentOS 6.5
- O2O 行业 IT 系统架构实践分享
- POJ-2115 C Looooops
- Linux内核学习总结
- 堆的实现(堆的建立及push、pop元素)
- nginx限制ip并发数
- nginx 403错误
- sqoop的使用
- CentOS 5 上使用yum同时安装32位和64位包的解决方法
- 巴什博奕(Bash Game)
- Ubuntu nginx 安装