首页 技术 正文
技术 2022年11月11日
0 收藏 365 点赞 4,042 浏览 2127 个字

Jessica’s Reading Problem

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12346   Accepted: 4199

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

Source

POJ Monthly–2007.08.05, Jerry
——————————————————————————————————————题目的意思是给出n页书本的信息,求最小的连续的页数能覆盖全部知识点思路:先记录有多少个不同知识点,由于数据较大开个map记录知识点处现的次数尺取法,如果知识点不够,先r++,在判是不是新知识,再更新map,如果够了,先l++,在更新map,在判是不是少了知识点

#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f;
int n,m;
int a[1000005];int main()
{
while(~scanf("%d",&n))
{
set<int>s;
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
s.insert(a[i]);
}
m=s.size();
map<int,int>mp;
int l=0,r=0;
int sum=0;
int ans=inf;
while(1)
{
while(r<n&&sum<m)
{
if(mp[a[r]]==0)
sum++;
mp[a[r++]]++;
}
if(sum<m) break;
ans=min(ans,r-l);
if(mp[a[l]]==1)
sum--;
mp[a[l++]]--;
}
if(ans==inf)
ans=0;
printf("%d\n",ans);
}
return 0;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898