POJ3320 Jessica ' s Reading problem
Set is used to count the number of all non-repeating knowledge points, and map is used to maintain the number of occurrences of each knowledge point on the interval [s,t], which is a good representation of the flexible application of map
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<vector>#include<map>#include<Set>#include<string>#include<cmath>using namespacestd;Const intINF =0x3f3f3f3f; typedefLong Longll;Const intMax_p =1000010;intP;inta[max_p];intMain () {scanf ("%d", &q); for(inti =0; i < P; ++i) {scanf ("%d", &A[i]); } Set<int>All ; for(inti =0; i < P; ++i) {All.insert (a[i]); } intn =all.size (); ints =0, t =0, num =0; Map<int,int>count; intres =P; for (;;) { while(T < P && Num <N) {if(count[a[t]]==0) {//There's a new point of knowledge .num++; } Count[a[t]]++; T++; } if(Num < N) Break; Res= min (res, t-s);//Update minimum interval lengthcount[a[s]]--; if(Count[a[s]] = =0)//0 Occurrences of a knowledge point{num--; } s++; } printf ("%d\n", RES); return 0;}
POJ3320 Jessica ' s Reading problem (ruler take +map+set)