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 P non-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

5
1 8 8 8 1

Sample Output

2

题意:求最短的 连续的子序列 使得出现所给序列中所有不同的数 输出长度
题解:记录左边界head=1
每次将右边位置向右移动一下,当出现a[i]==a[head]时尝试移动左边界
什么时候能移动呢?当最左边的数的计数大于1时移动 也就是最左边的数在当前区间出现次数>1
取满足条件的区间长度的最小值;

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
#define ll long long
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int p;
int a[];
int zong=;
map<int,int>mp;
int main()
{
while(~scanf("%d",&p))
{
mp.clear();
zong=;
for(int i=; i<=p; i++)
{
scanf("%d",&a[i]);
if(mp[a[i]]==)
zong++;
mp[a[i]]++;
}
mp.clear();
int ans=;
mp[a[]]=;
ans++;
int head=;
int maxn=p;
for(int i=; i<=p; i++)
{
if(mp[a[i]]==)
ans++;
mp[a[i]]++;
if(a[i]==a[head])
{
while(mp[a[head]]>)
{
mp[a[head]]--;
head++;
}
}
if(ans==zong)
maxn=min(maxn,i-head+);
}
printf("%d\n",maxn);
}
return ;
}

poj 3320 技巧/尺取法 map标记的更多相关文章

  1. Jessica's Reading Problem POJ - 3320(尺取法2)

    题意:n页书,然后n个数表示各个知识点ai,然后,输出最小覆盖的页数. #include<iostream> #include<cstdio> #include<set& ...

  2. poj 3320 jessica's Reading PJroblem 尺取法 -map和set的使用

    jessica's Reading PJroblem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9134   Accep ...

  3. POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 5896 Desc ...

  4. POJ 3320 Jessica's Reading Problem 尺取法/map

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7467   Accept ...

  5. POJ——3061Subsequence(尺取法或二分查找)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11224   Accepted: 4660 Desc ...

  6. poj 3061 题解(尺取法|二分

    题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 ...

  7. POJ 3061 Subsequence 尺取法

    转自博客:http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是两个指针表示区间[l,r]的开始与结束 然后根据题目来将端点移动,是一 ...

  8. POJ 3061 Subsequence(尺取法)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18145   Accepted: 7751 Desc ...

  9. POJ:3061-Subsequence(尺取法模板详解)

    Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18795 Accepted: 8043 Descript ...

随机推荐

  1. NOIP 2003解题报告

    第一题(神经网络): 题目大意,给出一些点,每个点都有2个值,c和u,给出一些有向边,权值为w.入度为0的点的c已知,其它点的c未知,每个入度不为0的点node的c等于sum(c[k]*w[k][no ...

  2. php头像上传并裁剪支持3个尺寸

    源码下载

  3. 长理ACM 14-星期几(谌海军)

    题目描述:编一个程序,已知今天是星期几,计算出n天后是星期几.要求使用枚举变量. 输入描述:输入为两个正整数,第一个数n(n<=6)表示今天是星期几,第二个数m(m<=1000),表示求m ...

  4. 关于java.lang.reflect.InvocationTargetException

    今天遇到java.lang.reflect.InvocationTargetException错误,卡了好一会儿,报错代码 try { Class<?> c= Class.forName( ...

  5. CSU1022

    题目: blue和AutoGerk是好朋友.他们的相同点是都喜欢研究算法,不同点是AutoGerk已是大牛而blue还是菜鸟.blue经常拿一些自以为很难的问题去问AutoGerk,想难倒他,但是每次 ...

  6. Maven 玩 github上的项目

    第一步,使用maven创建了一个项目"helloworld",cmd命令如下: @echo offecho [INFO] Generating project in ./gener ...

  7. Map学习

    1.Query Operations(查询操作) int size();boolean isEmpty(); boolean containsKey(Object key);boolean conta ...

  8. maven的简单安装与配置

    什么是Maven? Maven可以被理解成"知识的积累",也可以被翻译为"专家".它是一个项目管理工具. 它的主要服务即源于java平台的项目构建.依赖管理和项 ...

  9. JAVA 打印九九乘法表

    /** *  * @author liangxiaoyu * @version 1.0 *2015-09-18 */public class JJ { public static void main( ...

  10. uitabbarcontroller中 在设置tab bar item的image属性后不显示问题

    开始使用ios中的UITabBarController,在给Tab Bar Item设置自定义图片的时候,遇到了问题 按照如下配置: 出来的结果确是: 实际上test24.png应该是: 纠结了很久, ...