码迷,mamicode.com
首页 > 其他好文 > 详细

[2016-04-25][codeforces][665B - Shopping]

时间:2016-04-25 22:27:58      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

  • 时间:2016-04-25 20:52:11 星期一

  • 题目编号:[2016-04-25][codeforces][665B - Shopping]

  • 题目大意:已知n个货物的位置,已知每个客人需要的货物,问总共需要走多少次.

  • 分析:直接模拟

  1. #include<cstdio>
  2. #include<deque>
  3. using namespace std;
  4. deque<int> q;
  5. deque<int>::iterator itq;
  6. int main(){
  7. int n,m,k,tmp;
  8. scanf("%d%d%d",&n,&m,&k);
  9. for(int i = 0 ; i < k; ++i){
  10. scanf("%d",&tmp);
  11. q.push_back(tmp);
  12. }
  13. int ans = 0;
  14. for(int i = 0 ; i < n; ++i){
  15. for(int j = 0 ; j < m ; ++j){
  16. scanf("%d",&tmp);
  17. for(itq = q.begin();itq != q.end();++itq){
  18. if(*itq == tmp){
  19. ans += itq - q.begin() + 1;
  20. q.erase(itq);
  21. q.push_front(tmp);
  22. break;
  23. }
  24. }
  25. }
  26. }
  27. printf("%d\n",ans);
  28. return 0;
  29. }




[2016-04-25][codeforces][665B - Shopping]

标签:

原文地址:http://www.cnblogs.com/qhy285571052/p/b97db9e5ba95d817330e211278d8fc47.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!