zoukankan      html  css  js  c++  java
  • hihoCoder#1086 Browser Caching

    原题地址

    list+map可以轻松搞定,如果不借助STL实现起来还是挺麻烦的

    代码:

     1 #include <iostream>
     2 #include <string>
     3 #include <list>
     4 #include <map>
     5 
     6 using namespace std;
     7 
     8 int N, M;
     9 map<string, list<string>::iterator> record;
    10 list<string> cache;
    11 int size = 0;
    12 
    13 int main() {
    14   string url;
    15 
    16   cin >> N >> M;
    17   while (N--) {
    18     cin >> url;
    19     auto p = record.find(url);
    20     if (p != record.end()) {
    21       cache.erase(p->second);
    22       cache.push_front(p->first);
    23       cout << "Cache" << endl;
    24     }
    25     else if (size >= M){
    26       record.erase(cache.back());
    27       cache.pop_back();
    28       cache.push_front(url);
    29       record.insert(pair<string, list<string>::iterator>(url, cache.begin()));
    30       cout << "Internet" << endl;
    31     }
    32     else {
    33       cache.push_front(url);
    34       size++;
    35       record.insert(pair<string, list<string>::iterator>(url, cache.begin()));
    36       cout << "Internet" << endl;
    37     }
    38   }
    39   return 0;
    40 }
  • 相关阅读:
    团队项目-BUG挖掘
    评论任务
    4-14结对-复利计算
    做汉堡-结对
    复利计算--结对
    input上传按钮的优化
    avalon.js与 ajax使用的一个错误实例
    去除list集合中重复项的几种方法
    mvc学习记录
    常用js正则
  • 原文地址:https://www.cnblogs.com/boring09/p/4423290.html
Copyright © 2011-2022 走看看