hihocdoer 1086 : Browser Caching
来源:互联网 发布:crm软件系统功能 编辑:程序博客网 时间:2024/06/05 01:14
点击打开链接
描述
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 2www.bing.comwww.microsoft.comwww.microsoft.comwindows.microsoft.comwww.bing.com
InternetInternetCacheInternetInternet
#include<stdio.h>#include<stdlib.h>#include<iostream>#include<math.h>#include<vector>#include<string>#include<sstream>#include<algorithm>#include<stack>#include<queue>#include<limits.h>#include<numeric>#include<cstring>#include<map>#include<set>using namespace std;#define eps 1e-8#define LL long longconst LL mod=12357;const int MIN= -1e3;const int MAX= 128 ;const int MAX_N= 5e3 + 200;const int MAX_M = 1e5 + 10;const int MAX_K = 1e4+10;static int N, M, K, T;map <string ,int> lastvisit;int main() {cin >> N >> M;int s = 1, cacheNum = 0;vector<string> str_in;// 0 potint to empty stringstr_in.push_back("");for(int i = 1; i<=N; ++i) {string in;cin >> in;str_in.push_back(in);}for(int i =1; i<=N; ++i) {int index = lastvisit[ str_in[i] ];if( index != 0 && index >=s && index <=i) {cout << "Cache" << endl;}//in cache// update cacheelse {//updatecacheNum += 1;if(cacheNum > M) {// fulls ++;cacheNum --;}cout <<"Internet" << endl;}lastvisit[ str_in[i] ] = i;while(lastvisit[ str_in[s]] != s) {s ++;}} system("pause");return 0;}
- hihocdoer 1086 : Browser Caching
- Hihocoder 1086 Browser Caching
- Browser caching
- Browser Caching
- 【hihoCoder】#1086: Browser Caching (微软笔试题)
- 微软笔试题#1086 : Browser Caching LRC缓存实现
- Browser Caching for GWT RPC Response
- hiho一下 第六十二周Browser Caching
- hihocoder Browser Caching(字符串hash)
- hiho一下 第六十二周题目1 : Browser Caching
- 微软2015校园招聘 技术类职位在线笔试-题目1 : Browser Caching
- hiho一下 第六十二周 题目1 : Browser Caching stl 应用
- [hihoCoder太阁最新面经算法竞赛9] 题目一:Browser Caching (LRU缓存)
- browser
- browser
- Browser
- browser
- hihocdoer 1163 : 博弈游戏·Nim游戏
- 慧都控件网 2015-05-26 05:02:00 阅读(6098) 评论(0) 在上一篇程序员最喜爱的12个Android应用开发框架(一)中,我们为大家介绍了前6个Android应用开发框
- HDU 3681Prison Break(BFS+二分+状态压缩DP)
- jquery 生成表格,拆分,合并
- 【C# 上位机】C#上位机之多编辑框输出
- 优化mysql limit offset
- hihocdoer 1086 : Browser Caching
- Android AccessibilityService(辅助服务)学习
- java总结
- iOS UITextField实用实现手机账号344格式 —— HERO博客
- 【学习ios之路:UI系列】ios中常见的几种控件.(UISlider,UISwitch,UIStepper,UISegmentedControl)
- Android 关于“NetworkOnMainThreadException”解决办法
- hibernate一对一对应关系
- setTimeout()&&setInterval()实例
- Java面向对象(多态、抽象类、接口)