1, POJ 3320
2, Link: http://poj.org/problem?id=3320
3, Summary: ruler, Hash,map Mark
Reading review, p page book, a page has a knowledge point, continuous look at the minimum number of pages to read all the knowledge points
Must say, STL enough Dick.
#include <iostream>#include<cstring>#include<cmath>#include<queue>#include<algorithm>#include<cstdio>#include<map>using namespacestd;#defineLL Long Long#defineINF 0x3f3f3f3fConst intn=1000100;intP,a[n];map<int,int>n,x;intMain () { while(~SCANF ("%d",&p)) { for(intI=1; i<=p;i++) {scanf ("%d",&A[i]); N[a[i]]++; } intS=n.size ();//total category of records intL=1, r=1, ans=INF; while(true) { while((r<=p) && (X.size () <s)) {//to meet the range requirements, otherwise the right endpoint movesx[a[r++]]++; } if(X.size () <s) Break; Ans=min (ans,r-l); X[a[l++]]--; if(x[a[l-1]]<=0) X.erase (a[l-1]);//key point, within the range of this category number <=0, delete} printf ("%d\n", ans); } return 0;}
View Code
POJ 3320 ft., Hash,map Mark