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. day26-socket(server和client通信)

    # socket是应用层与TCP/IP协议通信的中间软件抽象层,它是一组接口.它把复杂的TCP/IP协议隐藏到socket #接口的后面,让socket去组织数据,以符合指定的协议. # socket ...

  2. demo4j解析xml

    1//先加入dom4j.jar包 2import java.util.HashMap; 3import java.util.Iterator; 4import java.util.Map; 5 6im ...

  3. 5-7 学生cpp成绩统计

    完成“学生cpp成绩计算”之后,修改Person和Student类,各自增加两个无参构造函数. 仍以Person类为基础,建立一个派生类Teacher,增加以下成员数据: int ID;//教师工号 ...

  4. 高可用性的mongo集群搭建

    mongoDB安装 参照:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 配置yum管理包 在路径/etc/y ...

  5. SPI以及IIC的verilog实现以及两者之间的对比

    一.SPI是一种常用的串行通信接口,与UART不同的地方在于.SPI可以同时挂多个从机,但是UART只能点对点的传输数据,此外SPI有四条线实现数据的传输,而UART采用的是2条实现串行数据的传输 1 ...

  6. mac osx 下 浏览器 开启 java

    工作环境mac osx 浏览器 chrome:63.0.3239.132 (Official Build) (64-bit)firefox: 57.0.4 (64 位)safari:Version 1 ...

  7. 【Linux_Shell 脚本编程学习笔记四、监控系统内存并报警企业案例脚本】

    前置知识:awk 参考学习博客:https://www.cnblogs.com/bugingcode/p/8287914.html awk 'BEGIN{ commands } pattern{ co ...

  8. 接口测试时返回的响应报json错误

    问题: 测试接口时,传入错误数据,最开始对于错误数据也返回了json数据的响应:后来传入错误数据,接口突然就没有返回json数据,通过在出错的代码之前进行打印,发现接口报500了 检查错误的方法1:在 ...

  9. python列表推导式(扫盲)

    1) 简单了解: 所谓的列表推导式,就是指的轻量级循环创建列表. 格式: 列表推导式的常见形式: my_list = [ item for item in iterable] my_list: 列表名 ...

  10. HashMap的四种遍历!

    HashMap的四种遍历 import java.util.Collection; import java.util.HashMap; import java.util.Map; import jav ...