poj3320
来源:互联网 发布:七匣子淘宝 编辑:程序博客网 时间:2024/06/12 00:36
Description
Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The author of that text book, like other authors, is extremely fussy about the ideas, thus some ideas are covered more than once. Jessica think if she managed to read each 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 her each page of Jessica's text-book with what idea each page is about and thus made a big progress for his courtship. Here you come in to save your skin: given the index, help Jessica decide which contiguous part she should read. For convenience, each idea has been coded with an ID, which is a non-negative integer.
Input
The first line of input is an integer P (1 ≤ P ≤ 1000000), which is the number of pages of Jessica's text-book. The second line contains Pnon-negative integers describing what idea each page is about. The first integer is what the first page is about, the second integer is what the second page is about, and so on. You may assume all integers that 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
代码:
/*踏实!!努力!!*/#include<iostream>#include<stdio.h>#include<cmath>#include<cstring>#include<map>#include<queue>#include<stack>#include<set>using namespace std;#define N 1000005int n,data[N];set<int>S;map<int,int>P;int main(){ while(scanf("%d",&n)!=EOF){ S.clear(); P.clear(); for(int i=0;i<n;i++){ scanf("%d",&data[i]); S.insert(data[i]); } int Min=n; int last=0,ans=S.size(),pre=0,now=0; while(1){ while(last<n&&now<ans){ if(!P[data[last]]) now++; P[data[last++]]++; } while(P[data[pre]]>1) P[data[pre++]]--; if(now==ans){ Min=min(Min,last-pre); now--; P[data[pre++]]--; } if(last==n) break; } printf("%d\n",Min); } return 0;}
- poj3320
- poj3320
- poj3320
- POJ3320
- poj3320(取尺法)
- poj3320 hash
- 尺取法--poj3320
- POJ3320 尺取
- poj3320(区间追逐)
- poj3320 尺取法
- 尺取法 poj3061 poj3320
- poj3320 尺取法~~
- POJ3320尺取法
- poj3320尺取法
- POJ3320尺取法
- 尺取法+POJ3320
- POJ3320 尺取法
- poj3320 尺取法
- MySQL学习总结1
- java学习笔记-------对卡片布局管理器的深入理解
- dpkg命令
- 新blog
- JTextArea设置滚动条
- poj3320
- SQL truncate 、delete与drop区别
- web.xml
- zigbee术语简介
- session与request
- python正则表达式 re (二)sub
- C# 反射
- 杭电 1503 Advanced Fruits(lcs)
- C++11 并发指南六( <atomic> 类型详解二 std::atomic )