您的位置:首页 > 其它

BZOJ1528 [POI2005]sam-Toy Cars

2014-12-14 19:28 225 查看
贪心的思想,每次如果要放回去的话,一定是那个下次时间最后的玩具。

于是直接用堆模拟玩一遍就好了。

蒟蒻表示只是懒了不想写struct用了pair结果各种报错各种跪你至于吗g++编译器!!!

/**************************************************************
Problem: 1528
User: rausen
Language: C++
Result: Accepted
Time:716 ms
Memory:13304 kb
****************************************************************/

#include <cstdio>
#include <queue>
#include <utility>

using namespace std;
const int N = 500005;

int n, k, p, ans;
int a
, next
, last
;
bool v
;
priority_queue <pair <int, int> > h;

int main() {
int i;
scanf("%d%d%d", &n, &k, &p);
for (i = 1; i <= n; ++i)
last[i] = p + 1;
for (i = 1; i <= p; ++i)
scanf("%d", a + i);
for (i = p; i; --i) {
next[i] = last[a[i]];
last[a[i]] = i;
}
for (i = 1; i <= p; ++i) {
if (v[a[i]])
h.push(make_pair(next[i], a[i])); else
if (k) {
h.push(make_pair(next[i], a[i]));
v[a[i]] = 1, --k, ++ans;
} else {
while (!v[h.top().second]) h.pop();
v[h.top().second] = 0, h.pop();
h.push(make_pair(next[i], a[i]));
v[a[i]] = 1, ++ans;
}
}
printf("%d\n", ans);
return 0;
}


View Code
(p.s. 忘了初始化last数组结果贡献1WA)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: