POJ-3320-Jessica's Reading Problem
来源:互联网 发布:java 多线程高层api 编辑:程序博客网 时间:2024/05/19 18:44
题目大意是说给你n个数,让你找到一个连续的最短区间,使得区间内含有所有n个数里面所出现的不同数。
思路:维护一个队列即可~
需要注意一点的是,判重只能用STL,因为数据量很大
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<set>#include<map>using namespace std;const int maxn=1e6+1000;int n,a[maxn],ans;set<int> s;map<int,int> f;int main(){ while(scanf("%d",&n)!=EOF) {s.clear();f.clear();for(int i=0;i<n;i++){ scanf("%d",&a[i]); s.insert(a[i]);}int cnt=s.size(),pre=0,last=0,now=0;ans=n;while(1){ while(last<n&&now<cnt) {if(!f[a[last]]) now++;f[a[last++]]++; } while(f[a[pre]]>1)f[a[pre++]]--; if(now==cnt) {ans=min(ans,last-pre);f[a[pre++]]--;now--; } if(last==n)break;}printf("%d\n",ans); } return 0;}
0 0
- POJ:3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- POJ-3320-Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- Jessica's Reading Problem POJ 3320
- POJ 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- POJ-3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- poj-3320-Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- leetCode: Word Break I & Word Break II
- Android经典的大牛博客推荐
- 如何设定指定logger的日志级别
- HDU 1219AC Me
- iOS 中如何去调用相机和相册的图片,详解
- POJ-3320-Jessica's Reading Problem
- 【poj2157】Maze
- UVa 10282 - Babelfish STL Map
- 2013蓝桥杯 CC++程序设计本科A组 连号区间数
- iphone通讯录AddressBook.framework和AddressBookUI.framework的应用
- 平衡二叉树实现
- 学习scikit learn 1
- Qt子线程更新主线程方法
- Java基础——对象