Jessica's Reading Problem POJ - 3320

时间:2022-09-23 21:11:54
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&&num;39&semi;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&colon;Jessica&&num;39&semi;s Reading Problem&lpar;POJ 3320&rpar;

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

  3. Jessica&&num;39&semi;s Reading Problem POJ - 3320(尺取法2)

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

  4. 尺取法 POJ 3320 Jessica&&num;39&semi;s Reading Problem

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

  5. POJ 3320 Jessica&&num;39&semi;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&plus;set&plus;尺取法

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

  7. POJ 3320 Jessica&&num;39&semi;s Reading Problem 尺取法&sol;map

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

  8. POJ 3220 Jessica&&num;39&semi;s Reading Problem

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

  9. POJ3320 Jessica&&num;39&semi;s Reading Problem 2017-05-25 19&colon;55 38人阅读 评论&lpar;0&rpar; 收藏

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

随机推荐

  1. &lbrack;课程设计&rsqb;Scrum 2&period;6 多鱼点餐系统开发进度&lpar;下单一览页面-菜式添加功能实现&rpar;

    Scrum 2.6 多鱼点餐系统开发进度  (下单一览页面-菜式添加功能实现) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题 ...

  2. codeforces B&period;Fence 解题报告

    题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数 ...

  3. JS中的substring和substr函数的区别

    1. 在JS中, 函数声明: stringObject.substring(start,stop) start是在原字符串检索的开始位置,stop是检索的终止位置,返回结果中不包括stop所指字符. ...

  4. filter过滤器执行顺序

    浏览器请求---->进入过滤器---->进入doFilter方法--->执行chain.doFilter()方法就会放行----->进入业务逻辑方法------>进入过滤 ...

  5. Qt控制台和带窗口的区别&lowbar;mickelfeng&lowbar;新浪博客

    Qt控制台和带窗口的区别_mickelfeng_新浪博客     t控制台和带窗口的区别    (2012-04-30 10:50:53)    标签:    杂谈        分类: C/C    ...

  6. Android 正则表达式验证手机号、姓名(包含少数民族)、身份证号

    最近项目中新增的功能,需要对手机号.姓名.身份证号等一些信息进行验证,最好的方法是通过正则表达式来验证,网上查了一些资料,写了这几个工具方法. 1.验证手机号 规则:第一位只能是1,第二位为3-8中的 ...

  7. LoveIsIntheAir模板换背景

    /*simplememory*/#google_ad_c1, #google_ad_c2 {display:none;}.LoveIsIntheAir a, .LoveIsIntheAirdiv, . ...

  8. Delphi 7~XE系列升级安装Indy10&period;6

    由于低版本Indy无法满足网络技术的日益更新,如SSL/TLS请求.RawHeaders与Cookie管理等问题处理. 我本身一直在用Delphi 2007,因为D2009开始底层的编码已不同,旧项目 ...

  9. 使用git工具删除github上的文件或者文件夹

    解决 使用git工具删除github上的文件或者文件夹 当我们需要从github上删除一些我们不需要的文件或者文件夹时,如果通过github来操作的话,将会很麻烦,因为github只允许删除一个仓库, ...

  10. Javascript模块化工具require&period;js教程

    转自:http://www.w3cschool.cc/w3cnote/requirejs-tutorial-1.html, http://www.w3cschool.cc/w3cnote/requir ...