入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

【hihocoder】Browser Cache

创建时间:2015-09-06 投稿人: 浏览次数:118

本题根据hihocoder oj提供的解题报告编写:

http://hihocoder.com/discuss/question/2154


/**
 *  @author         johnsondu
 *  @createTime     2015.09.06 15:59
 *  @problem        hihocoder: Browser Caching
 *  @url            http://hihocoder.com/contest/hiho62/problem/1
 *  @type           simple simulation of LRU cache
 */


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
using namespace std;

const int N = 20005;
int n, m;
map<string, int> lastVisit;
string a[N];

int main()
{
    scanf("%d%d", &n, &m);
    int cacheCnt = 0;
    int start = 1;

    for(int i = 1; i <= n ; i ++)
    {
        cin >> a[i];
        if(lastVisit[a[i]] >= start &&
            lastVisit[a[i]] <= i) printf("Cache
");
        else {
            printf("Internet
");
            cacheCnt ++;
            // 缓存已满
            if(cacheCnt > m) {
                start = start + 1;
            }
        }
        //更新最后一次访问时间
        lastVisit[a[i]] = i;
        //更新s找到最新的最早的访问记录
        while(lastVisit[a[start]] != start)
            start = start + 1;
    }

    return 0;
}


声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像