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
Source POJ monthly--2007.08.05, Jerry. |
The main topic: give you n number, different numbers represent different knowledge points, to find the minimum number of pages, so as to cover all the knowledge points
Puzzle: And Interval summation is similar, the ruler of the O (n) pointer from the beginning has been expanded, with a map to save knowledge points.
#include <map>#include<stdio.h>using namespaceStd;map<int,int>MP1, MP;inta[1234567];intMain () {intn, i, num, z, y, sum, l; while(SCANF ("%d", &n)! =EOF) {mp.clear (); Mp1.clear (); for(i=0; i<n;i++) {scanf ("%d", &A[i]); Mp[a[i]]++; } num=mp.size (); Sum=z=y=0; L=N; while(1) { while(y<n&&sum<num)if(mp1[a[y++]]++==0) Sum++; if(Sum<num) Break; L= min (l, yz); if(--mp1[a[z++]]==0) Sum--; } printf ("%d\n", L); } return 0;}
POJ 3320 Jessica ' s Reading problem ruler extraction