Jessica's Reading Problem
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17562   Accepted: 6099

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

 
题意:有n页书涵盖所有知识点,求涵盖所有知识点的连续页总数的最小值
思路:尺取法 用set、map、queue进行维护就好了哒~
accode
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define MAX_N 1000005
#define gcd(a,b) __gcd(a,b)
#define mem(a,x) memset(a,x,sizeof(a))
#define mid(a,b) a+b/2
#define stol(a) atoi(a.c_str())//string to long
int temp[MAX_N];
int main(){
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("D:\\in.txt","r",stdin);
// freopen("D:\\out.txt","w",stdout);
// #else
// #endif
int n;
queue<int> que;
set<int> iset;
map<int,int> imap;
scanf("%d",&n);
for(int i = ; i < n; i++){
scanf("%d",&temp[i]);
iset.insert(temp[i]);
}
int k = iset.size();
iset.clear();
int res = inf;
for(int i = ; i < n; ++i){
iset.insert(temp[i]);
que.push(temp[i]);
imap[temp[i]]++;
if(iset.size() == k){
// printf("%d\n",i);
res = min(res,(int)que.size());
}
while(iset.size() == k){
int a = que.front();
imap[a]--;
que.pop();
if(imap[a]==){
res = min(res,(int)que.size()+);
iset.erase(a);
} } }
printf("%d\n",res);
return ;
}

Jessica's Reading Problem POJ - 3320的更多相关文章

  1. A - Jessica's Reading Problem POJ - 3320 尺取

    A - Jessica's Reading Problem POJ - 3320 Jessica's a very lovely girl wooed by lots of boys. Recentl ...

  2. Greedy:Jessica's Reading Problem(POJ 3320)

    Jessica's Reading Problem 题目大意:Jessica期末考试临时抱佛脚想读一本书把知识点掌握,但是知识点很多,而且很多都是重复的,她想读最少的连续的页数把知识点全部掌握(知识点 ...

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

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

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

    题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> ...

  5. POJ 3320 Jessica's Reading Problem

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

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

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

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

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

  8. POJ 3220 Jessica's Reading Problem

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

  9. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

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

随机推荐

  1. SpringBoot开发二十-Redis入门以及Spring整合Redis

    安装 Redis,熟悉 Redis 的命令以及整合Redis,在Spring 中使用Redis. 代码实现 Redis 内置了 16 个库,索引是 0-15 ,默认选择第 0 个 Redis 的常用命 ...

  2. 利用数目找中位数(牛客第七场E)

    https://ac.nowcoder.com/acm/contest/887/E 树状数组做法(代码有注释) #include<bits/stdc++.h> using namespac ...

  3. mysql安装后,进DOS输入命令mysql,提示错误:mysql ERROR 1045 (28000)的解决办法

    一.修改my.ini文件,并重启mysql服务 找到配置文件my.ini  ,然后将其打开,可以选择用记事本打开 打开后,搜索mysqld关键字,找到后,在mysqld下面添加skip-grant-t ...

  4. python学习笔记(1)python数据类型

    一.数据类型计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要 ...

  5. centos 6.* 修改时间

    一.查看Centos的时区和时间 1.使用date命令查看Centos时区 [root@VM_centos ~]# date -R Mon, 26 Mar 2018 19:14:03 +0800 2. ...

  6. insecticide|contradictions| at large|delay doing|

    N-MASS 杀虫剂;杀虫药Insecticide is a chemical substance that is used to kill insects. Spray the plants wit ...

  7. ASP.NET MVC4网站搭建与发布【最新】

    ASP.NET MVC4网站搭建与发布 一些往事 2015年,仅仅大二的我怀着一颗创业之心,加入了常熟派英特,成为阳光职场平台的创始之一,并肩负了公司技术部的大梁,当时阳光职场正在从线下服务向互联网化 ...

  8. web虚拟主机的三种配置方法

  9. 统一管理jar包版本

    <!-- 统一管理jar包版本 --> <properties> <spring.version>5.0.2.RELEASE</spring.version& ...

  10. Linux上SVN安装

    SVN,Subversion,是一个开源的版本控制系统. svn有两种运行方式:独立的服务器和借助apache运行,各有利弊.