Operating system hdu 2835 OPT
Operating system
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 659 Accepted Submission(s): 207
Each test case begins with three integers(C,N,B), separated by single spaces, telling you how many objects fit in the cache, 0 < C ≤ 10000, how many different objects are in the system, C ≤ N ≤ 100000, and how many accesses, 0 ≤ B ≤ 100000, will occur. The following line contains B integers between 0 and N-1 (inclusive) indicating what object is accessed.
- #include <iostream>
- #include <stdio.h>
- #include <algorithm>
- #include <math.h>
- #include <string.h>
- #include <set>
- #include <queue>
- using namespace std;
- typedef struct abcd
- {
- int p,last;
- } abcd;
- abcd a[];
- int flag[];
- int main()
- {
- int c,n,b,i,j,now,ans;
- while(~scanf("%d%d%d",&c,&n,&b))
- {
- for(i=; i<n; i++)flag[i]=;
- for(i=; i<b; i++)
- scanf("%d",&a[i].p);
- for(i=b-; i>=; i--)
- {
- a[i].last=flag[a[i].p];
- flag[a[i].p]=i;
- }
- ans=now=;
- memset(flag,,sizeof(flag));
- priority_queue<pair<int,int> > q;
- while(!q.empty())q.pop();
- for(i=; i<b; i++)
- {
- if(now<c)
- {
- if(flag[a[i].p])
- {
- q.push(make_pair(a[i].last,a[i].p));
- }
- else
- {
- flag[a[i].p]=;
- now++;
- ans++;
- q.push(make_pair(a[i].last,a[i].p));
- }
- }
- else
- {
- if(flag[a[i].p])
- {
- q.push(make_pair(a[i].last,a[i].p));
- }
- else
- {
- ans++;
- while(flag[q.top().second]==)q.pop();
- pair<int,int >t=q.top();
- q.pop();
- flag[a[i].p]=;
- flag[t.second]=;
- q.push(make_pair(a[i].last,a[i].p));
- }
- }
- }
- cout<<ans<<endl;
- }
- }
Operating system hdu 2835 OPT的更多相关文章
- OSMC Vs. OpenELEC Vs. LibreELEC – Kodi Operating System Comparison
Kodi's two slim-and-trim kid brothers LibreELEC and OpenELEC were once great solutions for getting t ...
- DBCC CHECKDB 遭遇Operating system error 112(failed to retrieve text for this error. Reason: 15105) encountered
我们一个SQL Server服务器在执行YourSQLDBa的作业YourSQLDba_FullBackups_And_Maintenance时遇到了错误: Exec YourSQLDba.Maint ...
- The World's Only Advanced Operating System
The World's Only Advanced Operating System
- Unable to open the physical file xxxx. Operating system error 2
在新UAT服务器上,需要将tempdb放置在SSD(固态硬盘)上.由于SSD(固态硬盘)特性,所以tempdb的文件只能放置在D盘下面,而不能是D盘下的某一个目录下面. ALTER DATABASE ...
- CREATE FILE encountered operating system error 5(Access is denied.)
这篇博文主要演示"CREATE FILE encountered operating system error 5(Access is denied.)"错误如出现的原因(当然只是 ...
- Linux启动报错missing operating system
用UltraISO制作了一个Red Hat Enterprise Linux Server release 5.7系统的U盘启动盘,然后在一台PC上安装,由于安装过程中在干别的事情,有些选项没有细看. ...
- Learning Roadmap of Robotic Operating System (ROS)
ROS Wiki: http://wiki.ros.org/ Robots Using ROS Textbooks: A Gentle Introduction to ROS Learning ROS ...
- Full exploitation of a cluster hardware configuration requires some enhancements to a single-system operating system.
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Operating System Desi ...
- Multiprocessor Operating System Design Considerations SYMMETRIC MULTIPROCESSORS
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION An SMP operating syst ...
随机推荐
- h5video标签
在video标签中,我们可以使用属性:videoWidth & videoHeight,它获取的是video的宽度和高度(媒体本身).虽然不能直接使用,但是可以通过计算宽高比得到 video ...
- window.onerror 应用实例
详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp75 window.onerror = function(sMessa ...
- poj 2455 二分+最大流
这个因为点少用邻接矩阵做的. 题意:求由1到n的t条不重复路径中最大边权值的最小值. 思路:先对边权进行排序,然后二分边权值,建图求从1到n的最大流,当最大流为t时便求出答案. 代码: #includ ...
- 通过createObjectURL实现图片预览
实现原理:通过createObjectURL 创建一个临时指向某地址的二进制对象. 过程:点击触发隐藏的 input file 的点击事件,使用createObjectURL读取 file,创建 ...
- JPG、PNG和GIF图片的基本原理及优…
JPG.PNG和GIF图片的基本原理及优化方法 一提到图片,我们就不得不从位图开始说起,位图图像(bitmap),也称为点阵图像或绘制图像,是由称作像素(图片元素)的单个点组成的.这些点可以进行不同的 ...
- 转:【Java并发编程】之二十三:并发新特性—信号量Semaphore(含代码)
载请注明出处:http://blog.csdn.net/ns_code/article/details/17524153 在操作系统中,信号量是个很重要的概念,它在控制进程间的协作方面有着非常重要的作 ...
- FFmpeg 常用命令收集
FFmpeg 常用命令 合并视频 ffmpeg -i "KTDS-820A_FHD.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts i ...
- 结对编程四则运算gui
码市地址:https://git.coding.net/linzhao/sizeyunsuangui.git 林 钊 -- 201421123105 吴世荣 -- 201421123119 王坤彬 - ...
- 使用properties配置文件为javabean注入属性值
①:实体类 package com.hts.entity; import java.io.Serializable; public class A implements Serializable{ p ...
- 使用Eclipse Egit与码云管理你的代码
总体流程: 建立远程仓库 建立本地仓库并与远程仓库关联 将Eclipse中的项目提交到本地仓库并进而push到远程仓库 一. 配置Eclipse EGit 图解Eclipse中安装及配置EGit插件中 ...