BZOJ1528 [POI2005]sam-Toy Cars
2014-12-14 19:28
225 查看
贪心的思想,每次如果要放回去的话,一定是那个下次时间最后的玩具。
于是直接用堆模拟玩一遍就好了。
蒟蒻表示只是懒了不想写struct用了pair结果各种报错各种跪你至于吗g++编译器!!!
View Code
(p.s. 忘了初始化last数组结果贡献1WA)
于是直接用堆模拟玩一遍就好了。
蒟蒻表示只是懒了不想写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)
相关文章推荐
- 【BZOJ 1528】 1528: [POI2005]sam-Toy Cars (贪心+堆)
- [BZOJ1528][POI2005]sam-Toy Cars(贪心)
- BZOJ 1528 [POI2005]sam-Toy Cars(优先队列)
- bzoj 1528: [POI2005]sam-Toy Cars
- 【bzoj1528】 [POI2005]sam-Toy Cars
- BZOJ1528: [POI2005]sam-Toy Cars
- bzoj1528 [POI2005]sam-Toy Cars
- BZOJ 1528 POI2005 sam-Toy Cars 堆+贪心
- 【BZOJ1528】[POI2005]sam-Toy Cars 贪心
- 【bzoj1528】[POI2005]sam-Toy Cars
- 【BZOJ 1528】[POI2005]sam-Toy Cars 贪心+堆
- [POI2005]SAM-Toy Cars
- BZOJ 1529 POI2005 ska Piggy banks 并查集
- BZOJ 1529: [POI2005]ska Piggy banks 并查集
- 【BZOJ】1537: [POI2005]Aut- The Bus
- bzoj2882 工艺(SAM+map)
- 【bzoj1532】[POI2005]Kos-Dicing
- bzoj1529: [POI2005]ska Piggy banks
- BZOJ 2946 SA/SAM
- bzoj 2882 工艺(SAM)