bzoj1293: [SCOI2009]生日礼物
2017-09-13 14:16
197 查看
考虑双指针,显然区间中必须有一种颜色一个,所以如果队首的元素在区间中出现过两次以上,就可以将它弹出。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; int read() { char ch=getchar();int f=0; while(ch<'0'||ch>'9')ch=getchar(); while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();} return f; } int sum[65],n,k,tot,num,ans=0x7fffffff; struct data { int col; int pla; }a[1000005]; int cmp(const data &x,const data &y) { return x.pla<y.pla; } int main() { n=read();k=read(); for(int i=1;i<=k;i++) { int m=read(); for(int j=1;j<=m;j++) { int x=read(); a[++tot].col=i; a[tot].pla=x; } } sort(a+1,a+n+1,cmp); int l=1; for(int i=1;i<=n;i++) { if(!sum[a[i].col]) num++; sum[a[i].col]++; while(sum[a[l].col]!=1) { sum[a[l].col]--; l++; } if(num==k) ans=min(ans,a[i].pla-a[l].pla); } //cout<<num; cout<<ans; }
相关文章推荐
- bzoj1293 [SCOI2009]生日礼物
- bzoj1293: [SCOI2009]生日礼物 单调队列
- bzoj1293: [SCOI2009]生日礼物(堆)
- bzoj1293[SCOI2009]生日礼物 尺取法
- bzoj1293 [SCOI2009]生日礼物 set暴力
- BZOJ1293(SCOI2009)[生日礼物]--维护区间
- BZOJ1293: [SCOI2009]生日礼物
- bzoj1293【SCOI2009】生日礼物
- bzoj1293 [SCOI2009]生日礼物 单调队列
- bzoj1293: [SCOI2009]生日礼物
- BZOJ1293 [SCOI2009]生日礼物 【队列】
- BZOJ1293 [SCOI2009]生日礼物
- BZOJ1293: [SCOI2009]生日礼物
- BZOJ1293: [SCOI2009]生日礼物
- BZOJ 1293: [SCOI2009]生日礼物【毛毛虫】
- bzoj 1293: [SCOI2009]生日礼物
- bzoj 1293: [SCOI2009]生日礼物 STL
- bzoj 1293: [SCOI2009]生日礼物
- 【BZOJ 1293】【SCOI 2009】生日礼物
- 【BZOJ1293】【SCOI2009】生日礼物