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

  • 时间: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. }


来自为知笔记(Wiz)


posted on 2016-04-25 20:55  红洋  阅读(146)  评论(0)    收藏  举报

导航