时间限制:1000ms
单点时限:10000ms
内存限制:256MB

描述

When you browse the Internet, browser usually caches some documents to reduce the time cost of fetching them from remote servers. Let's consider a simplified caching problem. Assume the size of browser's cache can store M pages. When user visits some URL, browser will search it in the cache first. If the page is already cached browser will fetch it from the cache, otherwise browser will fetch it from the Internet and store it in the cache. When the cache is full and browser need to store a new page, the least recently visited page will be discarded.

Now, given a user's browsing history please tell us where did browser fetch the pages, from the cache or the Internet? At the beginning browser's cache is empty.

输入

Line 1: Two integers N(1 <= N <= 20000) and M(1 <= M <= 5000). N is the number of pages visited and M is the cache size.

Line 2~N+1: Each line contains a string consisting of no more than 30 lower letters, digits and dots('.') which is the URL of the page. Different URLs always lead to different pages. For example www.bing.com and bing.com are considered as different pages by browser.

输出

Line 1~N: For each URL in the input, output "Cache" or "Internet".

提示

Pages in the cache before visiting 1st URL [null, null]

Pages in the cache before visiting 2nd URL [www.bing.com(1), null]

Pages in the cache before visiting 3rd URL [www.bing.com(1), www.microsoft.com(2)]

Pages in the cache before visiting 4th URL [www.bing.com(1), www.microsoft.com(3)]

Pages in the cache before visiting 5th URL [windows.microsoft.com(4), www.microsoft.com(3)]

The number in parentheses is the last visiting timestamp of the page.

样例输入

5 2
www.bing.com
www.microsoft.com
www.microsoft.com
windows.microsoft.com
www.bing.com

样例输出

Internet
Internet
Cache
Internet
Internet

翻译

时间限制:1000ms
单点时限:10000ms
内存限制:256MB

描述

当你浏览互联网,浏览器通常会缓存一些文件,以减少从远程服务器获取他们的时间成本。让我们考虑一个简单的缓存问题。假定浏览器的缓存可以存储第m页的大小。当用户访问某些网址,浏览器会首先搜索它在缓存中。如果页面已经被缓存的浏览器会从缓存中获取,否则浏览器会从互联网上获取它,并将其存储在缓存中。当缓存已满,浏览器需要存储一个新的页面,最近最少访问的页面将被丢弃。
现在,给定一个用户的浏览历史记录,请告诉我们没有浏览器那里获取网页,从高速缓存或互联网?在开始的时候浏览器的缓存是空的。

输入

第1行:两个整数N(1<= N<=20000)和M(1<= M<=5000)。 N是网页被访问的次数,M是高速缓存大小。
行2〜N + 1:每行包含由不超过30个低级字母,数字和点(“。”),这是该页面的URL的字符串。不同的URL总是导致不同的页面。例如www.bing.com和bing.com被认为是不同的网页浏览器所。

输出

线路1〜N:对于输入的每个网址,输出“高速缓存”或“互联网”。

提示

第一次访问URL之前的网页缓存中的[NULL,NULL]
第二次访问URL之前的页面高速缓存中的[www.bing.com(1),空]
第三次访问URL之前的页面高速缓存中的[www.bing.com(1),www.microsoft.com(2)]
第四次访问URL页面之前在缓存[www.bing.com(1),www.microsoft.com(3)]
第五次访问之前的页面高速缓存中的[windows.microsoft.com(4),www.microsoft.com(3)]
括号中的数字是该页面的最后访问的时间戳。

样例输入

5 2
www.bing.com
www.microsoft.com
www.microsoft.com
windows.microsoft.com
www.bing.com
样例输出
Internet
Internet
Cache
Internet
Internet


下面是我的代码

#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{int page_num,caoch_size,i;vector<int> page_count;vector<string> page_str;cin>>page_num>>caoch_size;string *page=new string[page_num];for(i=0;i<page_num;i++)cin>>page[i];string out1="Internet";string out2="Cache";vector<string>::iterator it1;vector<int>::iterator it2;for(i=0;i<page_num;i++){if(page_str.empty())//缓存中无网页{  page_str.push_back(page[i]);page_count.push_back(1);cout<<out1<<endl;continue;//结束本次循环}if(page_str.size()!=caoch_size)//缓存中还没满{vector<string>::iterator result = find( page_str.begin(), page_str.end(),page[i]); //查找是否出现过if(result==page_str.end())//缓存中没有{page_str.push_back(page[i]);page_count.push_back(1);cout<<out1<<endl;}else//缓存中存在{for(it1=page_str.begin(),it2=page_count.begin();it1!=result;++it1,++it2);//找到缓存中存放些网页的地址*it2+=1;//找到对应的位置计数加1cout<<out2<<endl;}}else//缓存中已满{//先查缓存中是否存在网页vector<string>::iterator result = find(page_str.begin(),page_str.end(),page[i]); //查找是否出现过if(result!=page_str.end())//缓存中已存在{for(it1=page_str.begin(),it2=page_count.begin();it1!=result;++it1,++it2);//找到缓存中存放些网页的地址*it2+=1;//对应的位置计数加1cout<<out2<<endl;}else//缓存中不存在{///从后面开始查找it1=page_str.end();it2=page_count.end();for(--it1,--it2;it1!=page_str.begin();--it1,--it2)//找到缓存中存放些网页的地址{if(*it2==1)//找到第1个只保留一次的位置{page_str.erase(it1);//把原来的删除page_count.erase(it2);page_str.push_back(page[i]);page_count.push_back(1);cout<<out1<<endl;break;}}///判断开头的位置if(*it2==1)//找到第1个只保留一次的位置{page_str.erase(it1);//把原来的删除page_count.erase(it2);page_str.push_back(page[i]);page_count.push_back(1);cout<<out1<<endl;}elsecout<<out1<<endl;///输入但不保存到缓存中}}}delete []page;system("pause");return 0;
}

微软2015校园招聘 技术类职位在线笔试-题目1 : Browser Caching相关推荐

  1. 微软2016校园招聘9月在线笔试题解

    微软2016校园招聘9月在线笔试题解 题目网址列表:http://hihocoder.com/contest/mstest2015sept2/problems 题目一分析: 问题描述:在二维坐标系中, ...

  2. [Hihocoder 1289] 403 Forbidden (微软2016校园招聘4月在线笔试)

    传送门 #1289 : 403 Forbidden 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi runs a web server. Someti ...

  3. 微软2016校园招聘4月在线笔试 hihocoder 1288 Font Size (模拟)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Steven loves reading book on his phone. The book he reads now ...

  4. 笔试 | 东方财富 2020 春季校园招聘后端开发在线笔试【Python】【C++】【字符串】【动态规划】

    东方财富 2020 春季校园招聘后端开发在线笔试[Python][C++][字符串][动态规划] 一.单选题 一共有 256 个结点的二叉树高度最小是多少:8. 读程题,选出正确的程序输出结果. 不记 ...

  5. 数据分析真题日刷 | 小红书2019年校园招聘数据分析岗位在线笔试第二批

    今日真题 小红书2019年校园招聘数据分析岗位在线笔试第二批(来源:牛客网) 题型 客观题:单选6道,不定项选择3道,填空3道: 主观题:问答2道 完成时间 120分钟 牛客网评估难度系数 3颗星 经 ...

  6. 数据分析真题日刷 | 小红书2019年校园招聘数据分析岗位在线笔试第一批

    今天是7月5日,进入「数据分析真题日刷」的第五套题啦,继续保持. 今日真题 小红书2019年校园招聘数据分析岗位在线笔试第二批(来源:牛客网) 题型 客观题:单选6道,不定项选择3道,填空3道 主观题 ...

  7. 【笔试题目整理】小红书2019年校园招聘数据分析岗位在线笔试第二批

    最近在准备数据分析岗位的笔试,整理了牛客网上的一些试题与答案方便查看(只摘部分). 今日真题 小红书2019年校园招聘数据分析岗位在线笔试第二批(来源:牛客网) 题型 客观题:单选6道,不定项选择3道 ...

  8. 【笔试题目整理】小红书2019年校园招聘数据分析岗位在线笔试第一批

    最近在准备数据分析岗位的笔试,整理了牛客网上的一些试题与答案方便查看. 本文转载出处: https://blog.csdn.net/weixin_44915703/article/details/94 ...

  9. 优酷土豆java面试_优酷土豆校园招聘Java开发类笔试题目

    先总体说下题型,共有20道选择题,4道简答题,3道编程题和1道扩展题,题目都比较简单,限时一小时完成, 一.选择题 选择题非常简单,都是基础题,什么死锁发生的条件.HashMap和HashSet查找插 ...

  10. 京东2015校园招聘技术类笔试题(笔试时间:2014-10-18)

    笔试时间:2014-10-18 笔试城市:深圳.广州等 笔试职位:技术类(包含各种职位) 答案: 一.1. A:HTTP协议是无状态的 http协议是无状态的,同一个client的这次请求和上次请求是 ...

最新文章

  1. fanuc机器人四边形编程_FANUC机器人示教编程:原始路径恢复功能介绍与使用方法...
  2. 在3ds Max中使用V-Ray 5渲染引擎视频教程
  3. 如何编码和解码base64字符串?
  4. numpy 加速心得
  5. Digital River拉来Netconcepts站台 亚太营销服务升级
  6. 小甲鱼 OllyDbg 教程系列 (十一) : inline patch ( 内嵌补丁 )
  7. c++中的运算符重载---知识点:运算符重载函数,友元函数,函数重载
  8. 游戏引擎中的通用编程技术
  9. 一位程序员的十年工作总结,值得每位互联网人看
  10. Android开发之——依赖冲突Program type already present
  11. MED-V实战之镜像测试,MED-V系列之五
  12. Python为什么取名为Python,很少人知道
  13. Python——私有化和动态添加属性和方法、Property、new和slots方法、单例、异常处理(day09)
  14. 广电物联网大赛正式开启
  15. 数据仓库系列:初识数仓
  16. canvas-绘制背景
  17. QT学习-超漂亮的软件登录界面模块
  18. PM、RD、QA、OP
  19. Hello Goodbye
  20. Day10QRadiobutton2021-09-24

热门文章

  1. ssm共享充电宝管理系统计算机毕业设计
  2. 【开发环境搭建】7. Vscode使用SFTP远程文件同步
  3. 一个在国内外使用广泛的精密电阻品牌介绍
  4. 【Python】import class/import module
  5. 简易2D横版RPG游戏制作
  6. 如何关闭伽卡他卡的开机自启
  7. 计算机网络基础冷知识,技术控必备冷知识
  8. 计算机网络 - 为什么能ping通 但是访问不了?
  9. [读书笔记—学习方法]《深度学习的艺术》-采铜
  10. 分享虚拟机VirtualBox安装win7系统完整步骤。