Title Address: http://poj.org/problem?id=3320
1#include <cstdio>2#include <iostream>3#include <string.h>4#include <algorithm>5#include <math.h>6#include <stdbool.h>7#include <time.h>8#include <stdlib.h>9#include <Set>Ten#include <map> One#include <stack> A#include <queue> -#include <vector> - using namespacestd; the #defineCLR (x, y) memset (x,y,sizeof (×)) - #defineSQR (x) ((x) * (x)) - #defineRep (i,a,b) for (int i= (a); i<= (b); i++) - #defineLL Long Long + #defineINF 0x3f3f3f3f - #defineA First + #defineB Second A Const intn=1e6+131; at intN,p,a[n]; - - voidSolve () - { - Set<int>All ; -map<int,int>count; in -scanf"%d",&p); to for(intI=0; i<p;i++) { +scanf"%d",&a[i]); - All.insert (A[i]); the } *n=all.size (); $ Panax Notoginseng intlb=0, ub=0, num=0; - intres=p; the while(true) { + while(Ub<p && num<N) { A if(count[a[ub++]]++ = =0) thenum++; + } - if(num<n) Break; $Res=min (res,ub-lb); $ if(--count[a[lb++]]==0) { -num--; - } the } - Wuyiprintf"%d\n", res); the - } Wu intMain () - { About solve (); $ return 0; -}
[POJ] 3320 Jessica ' s Reading problem (ruler)