POJ 3220 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的更多相关文章
- 尺取法 POJ 3320 Jessica's Reading Problem
题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> ...
- POJ 3320 Jessica's Reading Problem
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6001 Accept ...
- POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 5896 Desc ...
- POJ 3320 Jessica's Reading Problem 尺取法/map
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7467 Accept ...
- POJ 3320 Jessica's Reading Problem 尺取法
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- poj 3320 Jessica's Reading Problem(尺取法)
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- POJ 3320 Jessica's Reading Problem (尺取法)
Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is co ...
- POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...
- 题解报告:poj 3320 Jessica's Reading Problem(尺取法)
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
随机推荐
- 我看Java二十年:它是怎样永远改变编程的。
转自jdon的小文章:来自Infoworld的一篇纪念mod=viewthread&tid=3042" target="_blank">Java诞生20周年 ...
- CentOS 中使用yum出现的“UnicodeDecodeError: 'ascii' codec”问题解决方法
问题 新装了CentOS 6.5系统,打算使用yum安装程序是出现了例如以下错误: Loading mirror speeds from cached hostfile Traceback (most ...
- SpringMVC 常见异常处理
1.javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"request" ...
- SQL 2008 还原 SQL2005 备份文件 不成功的解决方法
解决方法1:不要在数据库名字上点右键选择还原,而要是在根目录“数据库”三个字上点右键选择还原,然后再选择数据库,问题便可以解决,如果不行参照方法2 解决方法2:写sql语句处理: RESTORE DA ...
- Flex之柱状图实例
Flex之柱状图实例 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns ...
- Zookeeper vs. etcd
etcd是go语言实现的. 对比,可以参考这篇文章: http://studygolang.com/articles/4837 <服务发现:Zookeeper vs etcd vs Consul ...
- BRep Shapes Based on Tessellated Geometry
BRep Shapes Based on Tessellated Geometry eryar@163.com Key Words. BRep Shape, Tessellated Geometry, ...
- wifidog用php实现验证流程
原创性声明 此博文的出处 为 http://blog.csdn.net/zhujunxxxxx/article/details/25384909假设进行转载请注明出处.本文作者原创,邮箱zhujunx ...
- 创建maven项目pom.xml出现错误(依赖Missing)
Maven的依赖问题 在聚合模块时候,发现在父工程目录中的依赖存在一些问题.一开始是${pagehelper.version},后来将版本直接填写相应的版本如图下 依赖添加失败 * 在父工程的jar包 ...
- FileStream vs/differences StreamWriter?
https://stackoverflow.com/questions/4963667/filestream-vs-differences-streamwriter What is different ...