1826: [JSOI2010]缓存交换
2018-07-06 18:20
190 查看
1826: [JSOI2010]缓存交换
https://www.lydsy.com/JudgeOnline/problem.php?id=1826
分析:
简单的贪心,然后调啊调。。。最近怎么了,码力大大下降,各种奇奇怪怪的bug漫天飞,以后少熬夜。
贪心:每次pop一定是pop最远点的点。
代码:
#include<bits/stdc++.h> using namespace std; typedef long long LL; inline int read() { int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1; for (;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f; } const int N = 100010; #define pa pair<int,int> #define mp(a,b) make_pair(a,b) priority_queue< pa > q; map<int,int> last,vis; int nxt ,a ; int main() { int n = read(),m = read(); for (int i=1; i<=n; ++i) nxt[i] = n+1; for (int i=1; i<=n; ++i) { a[i] = read(); if (last[a[i]]) nxt[last[a[i]]] = i; last[a[i]] = i; } int ans = 0,tot = 0; pa t; for (int i=1; i<=n; ++i) { if (vis[a[i]]) {q.push(mp(nxt[i],a[i]));continue;} if (tot == m) { tot --; while (!q.empty()) { t = q.top(); q.pop(); //--居然忘记写了!!! if (vis[t.second] == 0) continue; vis[t.second] = 0; break; } } ans++; q.push(mp(nxt[i],a[i])); tot ++; vis[a[i]] = 1; } cout << ans; return 0; }
相关文章推荐
- [BZOJ]1826: [JSOI2010]缓存交换 线段树
- bzoj 1826: [JSOI2010]缓存交换
- 1826: [JSOI2010]缓存交换
- BZOJ1826: [JSOI2010]缓存交换
- BZOJ 1826: [JSOI2010]缓存交换
- BZOJ_1826_[JSOI2010]缓存交换 _线段树+贪心
- bzoj1826: [JSOI2010]缓存交换
- 【bzoj 1826&1528】: [JSOI2010]缓存交换
- 1826: [JSOI2010]缓存交换
- 【优先队列+贪心】BZOJ1826-[JSOI2010]缓存交换
- [bzoj1826] [JSOI2010]缓存交换
- 【贪心】【JSOI2010】缓存交换
- bzoj1826: [JSOI2010]缓存交换 贪心+优先队列
- 【BZOJ】【P1826&P1528】【JSOI2010】【缓存交换】【题解】【堆+贪心】
- 【BZOJ1826】【tyvj2644】缓存交换,贪心+堆维护
- bzoj1822 [JSOI2010]Frozen Nova 冷冻波(计算几何+二分答案+最大流)
- bzoj 2208: [Jsoi2010]连通数
- bzoj千题计划201:bzoj1820: [JSOI2010]Express Service 快递服务
- Linux内存管理 —— 文件系统缓存和匿名页的交换
- BZOJ 1820: [JSOI2010]Express Service 快递服务( dp )