poj 3320 Jessica's Reading Problem(尺取法)

时间:2022-09-23 21:07:33

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 ( ≤ P ≤ ), 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

    

Sample Output


AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
#define N 1000006
int n;
int a[N];
set<int> se;
map<int,int>mp;
int main()
{
while(scanf("%d",&n)==){
se.clear();
mp.clear();
for(int i=;i<n;i++){
scanf("%d",&a[i]);
se.insert(a[i]);
}
int size_ = se.size();
int ans = n;
int s=,t=;
int num=;
while(){
while(t<n && num<size_){
if(mp[a[t]]==){
num++;
}
mp[a[t]]++;
t++;
}
if(num<size_) break;
ans=min(ans,t-s);
mp[a[s]]--;
if(mp[a[s]]==){
num--;
}
s++;
}
printf("%d\n",ans);
}
return ;
}

poj 3320 Jessica's Reading Problem(尺取法)的更多相关文章

  1. 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 ...

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

    Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...

  3. poj 3320 jessica&&num;39&semi;s Reading PJroblem 尺取法 -map和set的使用

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

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

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

  5. 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 ...

  6. POJ 3320 Jessica&&num;39&semi;s Reading Problem

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

  7. POJ 3320 Jessica&OpenCurlyQuote;s Reading Problem(哈希、尺取法)

    http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...

  8. POJ 3320&Tab;Jessica&&num;39&semi;s Reading Problem (尺取法)

    Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is co ...

  9. 题解报告:poj 3320 Jessica&&num;39&semi;s Reading Problem(尺取法)

    Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...

  10. poj3061 Subsequence&amp&semi;&amp&semi;poj3320 Jessica&&num;39&semi;s Reading Problem&lpar;尺取法&rpar;

    这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...

随机推荐

  1. Centos下MySQL主从同步配置

    说明:由于MySQL不同版本之间的(二进制日志)binlog格式可能会不一样, 因此最好的搭配组合是Master的MySQL版本和Slave的版本相同或者更低,Master的版本肯定不能高于Slave ...

  2. maven在windows环境下加载settings&period;xml文件

    今天发现maven在windows环境下加载的settings.xml文件是c:下的,就算修改conf下的settings.xml里的<localRepository>给他明确指向也没用.

  3. (转载)http&lowbar;build&lowbar;query用法&comma;挺方便的

    (转载)http://www.cnblogs.com/zhja/archive/2012/11/10/2764174.html http_build_query (PHP 5) http_build_ ...

  4. 第一百三十二节,JavaScript,封装库--下拉菜单

    JavaScript,封装库--下拉菜单 封装库,增加了3个方法 shu_biao_yi_ru_yi_chu()方法,给元素设置鼠标移入移出事件,接收两个参数,参数是移入和移出时的执行函数(包含代码) ...

  5. Java Web使用Html5 FormData实现多文件上传

    前一阵子,迭代一个线上的项目,其中有一个图片上传的功能,之前用的ajaxfileupload.js来实现上传的,不过由于ajaxfileupload.js,默认是单文件上传(虽然可以通过修改源码的方法 ...

  6. 快速新建简单的koa2后端服务

    既然前端工程化是基于NodeJS,那么选择NodeJs做前后端分离部署也是理所应当的.其实只需要实现静态资源和代理的话,用nginx才是最好的选择,用NodeJS是为了日后能进一步在服务端上实现自动构 ...

  7. larave异步多图片上传的实现和注意事项及&dollar;file的对象函数

    要使用多图片上传,首先要在input添加multipart,同时注意name的参数要加[],不然,不算是数组.具体如下,注意绿色地方.如果是单张图片,把[]去掉,不要multiple; <inp ...

  8. centos ping www&period;baidu&period;com ping&colon; unknown host www&period;baidu&period;com

    [root@zabbix ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script nameserver 219.141.136.10

  9. 洛谷P4206 聪聪与可可

    无向简单图上给定s,t.每秒s先向t按照最短路走两步(优先节点编号较小的),然后t随机行动一步. 问期望多少秒相遇.n <= 1000 解: 这个s太蛇皮了...所以预处理一波. 然后不会,看题 ...

  10. bootstrap datepicker显示日历

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title&gt ...