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
Similar to poj3061, is also used as a ruler to solve, map each knowledge point with map to show the number of times can be.
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <map > #include <vector> #include <list> #include <set> #include <stack> #include <queue># Include <deque> #include <algorithm> #include <functional> #include <iomanip> #include < limits> #include <new> #include <utility> #include <iterator> #include <cstdio> #include < cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <ctime>using Namespace Std;int a[1000010];int Main () {int p; CIN >> P; Set<int> all; for (int i = 0; i < P; ++i) {scanf ("%d", &a[i]); All.insert (A[i]); } int n = all.size (); int s = 0, t = 0, num = 0; Map<int, int> count; int ans = p; while (1) {while (T < p && Num < n) if (count[a[t++]]++ = = 0) num++; if (num < n) Break ans = min (ans, t-s); if (--count[a[s++]] = = 0) num--; } cout << ans << endl; return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
poj3320 (Jessica ' s Reading problem) scale extraction