[bzoj1293][SCOI2009]生日礼物(莫队)
2017-09-29 17:02
411 查看
题目:
我是超链接题解:
枚举起点,每次加入点的时候加到k种。因为一个位置上会有好多珠子,你可以按照珠子移动而不是按照颜色移动;代码:
#include <cstdio> #include <algorithm> #include <iostream> #include <cmath> #define INF 1<<30 #define N 1000005 using namespace std; struct hh{int col,pos;}a ; int c[100]; int cmp(hh a,hh b){return a.pos<b.pos;} int main() { int n,k,i,j,num=0,cnt=0; scanf("%d%d",&n,&k); for (i=1;i<=k;i++) { int lo,x; scanf("%d",&lo);++num; for (j=1;j<=lo;j++) { scanf("%d",&x); a[++cnt].col=num; a[cnt].pos=x; } } sort(a+1,a+1+n,cmp); int l=1,r=0,now=0,ans=INF; while (l<=n) { while (now<k && r<n) { r++; if (c[a[r].col]==0) now++; c[a[r].col]++; } if (now>=k) ans=min(ans,a[r].pos-a[l].pos); c[a[l].col]--;if (!c[a[l].col]) now--; l++; } printf("%d",ans); }
相关文章推荐
- bzoj 1293: [SCOI2009]生日礼物
- [BZOJ 1293] SCOI 2009 生日礼物 · 单调队列
- 【堆】bzoj1293 [SCOI2009]生日礼物
- bzoj 1293: [SCOI2009]生日礼物 暴力
- BZOJ 1293 SCOI2009 生日礼物 堆
- [BZOJ 1293][SCOI2009]生日礼物:单调队列
- [BZOJ1293]SCOI2009生日礼物|贪心
- BZOJ 1293: [SCOI2009]生日礼物 链表模拟
- [BZOJ1293][SCOI2009]生日礼物-堆
- bzoj1293: [SCOI2009]生日礼物 贪心
- [BZOJ1293][SCOI2009]生日礼物(单调队列)
- 【bzoj 1293】[SCOI2009]生日礼物(乱搞|单调队列)
- [bzoj 1293][SCOI2009] 生日礼物
- 【BZOJ】1293 [SCOI2009]生日礼物 (这题有多种解法)
- 【BZOJ 1293】[SCOI2009]生日礼物
- 【bzoj 1293】[SCOI2009]生日礼物
- [bzoj1293][SCOI2009]生日礼物 单调队列优化dp
- BZOJ1293: [SCOI2009]生日礼物
- BZOJ 1293: [SCOI2009]生日礼物【单调队列】
- [bzoj1293][SCOI2009]生日礼物