标签:return def push -- pass scanf tar == bsp
。。。。
题目链接:
http://www.lydsy.com/JudgeOnline/problem.php?id=1528
用数组记录一下每次玩具下次出现的时间。。。然后每一次贪心把下次出现时间最迟的取出即可。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<iostream> #include<queue> #include<vector> #define inf 1000000 using namespace std; int n,k,p; int toy[600000],tim[110000],nxt[600000]; bool c[110000]; priority_queue< pair<int,int> ,vector< pair<int,int> > >q; int main(){ int ans=0; scanf("%d%d%d",&n,&k,&p); for(int i=1;i<=p;i++){ scanf("%d",&toy[i]); nxt[tim[toy[i]]]=i; tim[toy[i]]=i; nxt[i]=inf; } int js=0; for(int i=1;i<=p;i++){ if(c[toy[i]]==1){ q.push(make_pair(nxt[i],toy[i])); continue; } if(js==k){ while(c[q.top().second]==0) q.pop(); c[q.top().second]=0; q.pop(); js--; } js++; ans++; c[toy[i]]=1; q.push(make_pair(nxt[i],toy[i])); } printf("%d\n",ans); return 0; }
This passage is made by Iscream-2001.
标签:return def push -- pass scanf tar == bsp
原文地址:http://www.cnblogs.com/Yuigahama/p/7738453.html