LuoguP3069 [[USACO13JAN] cattle lineup Cow Lineup

Topic Link

Looked at the other chiefs of the article, why should control it right

It is actually a very simple simulation queue lying. . .

The difficulty lies in the meaning of the questions we have to analyze some within the legal range, the number of different species can not exceed k + 2

Oh, of course, due to the number of species is too large to be the kind of discrete , you can use the STL map

The rest is simulated, see the code:

 

#include<bits/stdc++.h>
using namespace std;
map<int,int> f;
int ty,tot,k,n,ans;
int type[100010];                   
int num[100010];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){            //输入+离散化 
        scanf("%d",&ty);                             
        if(f [TY]) of the type [i] = f [TY];      // appeared to the original number 
        the else of the type [i] = ++ TOT, f [TY] = TOT;    // no-show, the update number and recording 
    }
     int CNT = . 1 , head = . 1 ; NUM [type [ . 1 ]] ++ ;    
     for ( int I = 2 ; I <= n-; I ++ ) {
         the while (CNT> = K + 2 ) {                 // if the interval k + 2 is greater than the number of kinds when the left-right point until the data is less than k + 2 
            NUM [type [head]] - ;         
             iF (NUM [type [head]] == 0 )       // number of a species when reduced to zero , a interval type Save
               cnt-- ; 
            head ++ ; 
        } 
        IF (! NUM [type [I]]) CNT ++;        // Update 
        NUM [type [I]] ++ ; 
        ANS = max (ANS, NUM [type [I]]);     // update with this kind 
    } 
    the printf ( " % D " , ANS);
     return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/tonyshen/p/11766556.html