POJ 3220 Jessica's Reading Problem

时间:2022-09-23 21:11:42
Jessica's Reading Problem
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12944   Accepted: 4430

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

贪心
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a[],n,i,j,ans,inf;
set<int>s;
map<int,int>vis;
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
s.insert(a[i]);
}
i=;j=;inf=;
for(i=;i<n;i++)
{
while(ans<n && j<s.size())
{
if(vis[a[ans]]==) j++;
vis[a[ans]]++;
ans++;
}
if(j<s.size()) break;
inf=min(inf,ans-i);
if(--vis[a[i]]==) j--;
}
printf("%d\n",inf);
}
return ;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 一:Shell基础

    1.shell概述  shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用shell来启动,挂起,停止甚至是编写一些程序:  shell还是 ...

  2. WebApi传参总动员&lpar;填坑&rpar;

    本以为系列文章已经Over,突然记起来前面留了个大坑还没填,真是自己给自己挖坑. 这个坑就是: (body 只能被读取一次)Only one thing can read the body MVC和W ...

  3. FZU 2147 A-B Game

    A-B Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  4. 适合自己的vim配置文件

    主要用来写c++的:clang-completer这个是单独安装的,其他的都采用的vundle安装完成. clang-completer:只在centos7.2上安装成功过,6.4上失败了.先要安装一 ...

  5. pyqt样式表语法笔记

    pyqt样式表语法笔记 pyqt QSS python 样式表 因为软件课设的原因开始学习使用pyqt4,才发现原来它也有样式表,而且语法跟css基本相同,而且一些功能实现起来感觉比js要简单方便得多 ...

  6. 最短路径(Dijkstra算法&rpar;

    算法局限性:边的权值不能为负. 需要两个辅助数组dist[],path[],分别记录起点到各点的最短距离和最短路径 算法步骤: 1.根据起点v0初始化dist[]和path[]数组. 2.在剩下的点中 ...

  7. 实现ssr服务端渲染

    前言 前段时间寻思做个个人网站,然后就立马行动了.  个人网站如何实现选择什么技术方案,自己可以*决定.  刚好之前有大致想过服务端渲染,加载速度快,还有 SEO 挺适合个人网站的.  所以就自己造 ...

  8. 数据库连接池优化配置&lpar;druid&comma;dbcp&comma;c3p0&rpar;

    主要描述了数据库连接池参数配置的准则,针对常用的数据库连接池(c3p0,dbcp,druid)给出推荐的配置. 考虑因素 1:当前连接DB的规模   2:并发情况 3:执行db的响应时间 配置考虑 1 ...

  9. Redis 应该是存放的数据超出了范围

    使用ServiceStack操作Redis 发生了 System.*Exception HResult=0x800703E9 Source=<无法计算异常源> St ...

  10. java字符串常量池——字符串&equals;&equals;比较的一个误区

    转自:https://blog.csdn.net/wxz980927155/article/details/81712342   起因 再一次js的json对象的比较中,发现相同内容的json对象使用 ...