[luoguP2564][SCOI2009]生日礼物(队列)
2017-05-01 20:55
218 查看
当然可以用队列来搞啦。
# include <iostream> # include <cstdio> # include <cstring> # include <string> # include <cmath> # include <vector> # include <map> # include <queue> # include <cstdlib> # include <algorithm> # define MAXN 1000001 using namespace std; inline int get_num() { int k = 0, f = 1; char c = getchar(); for(; !isdigit(c); c = getchar()) if(c == '-') f = -1; for(; isdigit(c); c = getchar()) k = k * 10 + c - '0'; return k * f; } int n, k, tot, sum, h, t, ans = 1 << 30; int num[MAXN]; struct node { int a, pos; }p[MAXN]; inline bool cmp(node x, node y) { return x.pos < y.pos; } int main() { int i, j, m; n = get_num(); k = get_num(); for(i = 1; i <= k; i++) for(j = 1, m = get_num(); j <= m; j++) p[++tot].a = i, p[tot].pos = get_num(); sort(p + 1, p + n + 1, cmp); for(h = 1, t = 0; h <= n; h++) { while(sum < k && t < n) { if(!num[p[++t].a]) sum++; num[p[t].a]++; } if(sum == k) ans = min(ans, p[t].pos - p[h].pos); num[p[h].a]--; if(!num[p[h].a]) sum--; } printf("%d", ans); return 0; }View Code
相关文章推荐
- [luoguP2564] [SCOI2009]生日礼物(队列)
- 【bzoj 1293】[SCOI2009] 生日礼物 指针维护队列
- [bzoj1293][SCOI2009]生日礼物(单调队列)
- bzoj 1293: [SCOI2009]生日礼物 (单调队列)
- bzoj1293 [SCOI2009]生日礼物 单调队列
- 【bzoj 1293】[SCOI2009]生日礼物(乱搞|单调队列)
- BZOJ 1293: [SCOI2009]生日礼物【单调队列】
- bzoj 1293: [SCOI2009]生日礼物【单调队列】
- bzoj1293: [SCOI2009]生日礼物 单调队列
- [BZOJ1293][SCOI2009]生日礼物(单调队列)
- BZOJ1293 [SCOI2009]生日礼物 【队列】
- [BZOJ 1293] SCOI 2009 生日礼物 · 单调队列
- [BZOJ 1293][SCOI2009]生日礼物:单调队列
- [bzoj1293][SCOI2009]生日礼物 单调队列优化dp
- [SCOI2009]生日礼物(单调队列)
- BZOJ 1293: [SCOI2009]生日礼物【毛毛虫】
- BZOJ1293: [SCOI2009]生日礼物
- [SCOI2009]生日礼物-暴力-排序-双指针
- bzoj 1293: [SCOI2009]生日礼物
- 1293: [SCOI2009]生日礼物 - BZOJ