zoukankan      html  css  js  c++  java
  • [洛谷P1638]逛画展

    [洛谷P1638]逛画展

    题目大意:

    (n(nle10^6))个格子,每个格子有一种颜色。颜色种数为(m(mle2000))。求包含所有颜色的最小区间。

    思路:

    尺取法裸题。

    思路:

    #include<cstdio>
    #include<cctype>
    #include<climits>
    inline int getint() {
    	register char ch;
    	while(!isdigit(ch=getchar()));
    	register int x=ch^'0';
    	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
    	return x;
    }
    const int N=1e6+1,M=2001;
    int a[N],cnt[M],tot;
    int main() {
    	const int n=getint(),m=getint();
    	for(register int i=1;i<=n;i++) {
    		a[i]=getint();
    	}
    	int min=INT_MAX,b,e;
    	for(register int l=1,r=0;l<=n;l++) {
    		for(;tot<m&&r<n;) {
    			if(!cnt[a[++r]]++) tot++;
    		}
    		if(tot==m) {
    			if(r-l+1<min) {
    				min=r-l+1;
    				b=INT_MAX;
    			}
    			if(r-l+1==min&&l<b) {
    				b=l,e=r;
    			}
    		}
    		if(!--cnt[a[l]]) tot--;
     	}
     	printf("%d %d
    ",b,e);
    	return 0;
    }
    
  • 相关阅读:
    Delphi 学习笔记
    Extjs 4
    面向对象(OOP)
    Java基础
    Ubantu(乌班图)
    CentOS 6.3操作常识
    英语音标单元音篇
    英语音标双元音篇
    英语音标辅音篇
    Oracle补习班第一天
  • 原文地址:https://www.cnblogs.com/skylee03/p/9870183.html
Copyright © 2011-2022 走看看