Part I: Topics
Description
Jessica ' s a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she had spent little time on it. If She wants to pass it, she had to master all ideas included in a very thick the text book. The author of that text book, like other authors, was extremely fussy about the ideas, thus some ideas was covered more tha N once. Jessica think if she managed to read all idea at least once, she can pass the exam. She decides to read only one contiguous part of the book which contains all ideas covered by the entire book. And of course, the sub-book should be as thin as possible.
A very hard-working boy had manually indexed for hers each page of the Jessica ' s text-book with what's idea each page was about an D thus made a big progress for his courtship. Here you come on to save your Skin:given the index, help Jessica decide which contiguous part she should read. For convenience, the idea had been coded with an ID, and which is a non-negative integer.
Input
The first line of input is a integer p (1≤ P ≤1000000), which is the number of pages of Jessica ' s Tex T-book. The second line contains P non-negative integers describing what's the idea of each page was about. The first integer is what the first page was about, the second integer was what the second page was about, and so on. Assume all integers this appear can fit well in the signed 32-bit integer type.
Output
Output one line:the number of pages of the shortest contiguous part of the book which contains all ideals covered in the Book.
Sample Input
51 8 8) 8 1
Sample Output
2
Part II: Code
/*Learn to use set, map to simplify operations. */#include<iostream>#include<stdio.h>#include<Set>#include<map>using namespacestd;intMain () {intpage[1000010],n; CIN>>N; //how many different points of knowledge are calculated using features that do not exist in the same element in set Set<int>All ; for(intI=0; i<n;i++) {scanf ("%d",&Page[i]); //cin>>page[i];//the use of CIN here is really slow, the thief is slowAll.insert (Page[i]); } intPoint=all.size ();//how many different points of knowledge are there?//Ruler: Popular point, is a section to see ints=0, t=0, num=0; intmin=N; Map<int,int> Fuck;//number of occurrences of knowledge points while(1) { while(t<n&&num<Point ) { //new points of knowledge appear if(fuck[page[t++]]++==0) {num++; } } if(num<Point ) { Break; } if(min>t-s) {min=t-s; } //removed a point of knowledge if(--fuck[page[s++]]==0) {num--; }} cout<<min<<Endl; return 0;}
View Code
Jessica ' s Reading problem