POJ 3320 Jessica's Reading Problem 尺取法
来源:互联网 发布:java磁条读卡器 编辑:程序博客网 时间:2024/05/31 05:27
题目:
http://poj.org/problem?id=3320
题意:
给出一个数列,求拥有数列中所有元素的一段连续子序列的最小长度
思路:
首先去重求出数列中元素的个数,然后尺取
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <set>using namespace std;const int N = 1000010, INF = 0x3f3f3f3f;int arr[N];int main(){ int n; while(~ scanf("%d", &n)) { map<int, int> mpa; set<int> ste; for(int i = 1; i <= n; i++) scanf("%d", &arr[i]), ste.insert(arr[i]); int en = 1, res = INF, num = 0, s = ste.size(); for(int i = 1; i <= n; i++) { while(en <= n && num < s) if(++mpa[arr[en++]] == 1) num++; if(num >= s) res = min(res, en - i); if(--mpa[arr[i]] == 0) num--; } printf("%d\n", res); } 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 【尺取法+STLmap set】
- poj 3320 Jessica's Reading Problem(尺取法+map/hash)
- POJ 3320 Jessica's Reading Problem(尺取法)
- POJ - 3320 Jessica's Reading Problem(尺取法)
- poj 3320 Jessica's Reading(尺取法 + Hash) Problem
- POJ - 3320 Jessica's Reading Problem(尺取法)
- poj 3320 Jessica's Reading Problem 【尺取法】
- poj 3320 Jessica's Reading Problem(尺取法)
- POJ-3320Jessica'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(尺取法)
- java中遍历实体类属性和类型,属性值
- 闰年判断
- C与指针 六 一些字符函数
- oracle 把datafile的size用resize方法变成最小
- js案例-4-经典tab栏切换
- POJ 3320 Jessica's Reading Problem 尺取法
- opensips安装配置
- C语言初级小例题矩阵对角线求和
- CentOS7 启用root用户
- 01字串
- iOS二维码限制扫描区域的问题记录
- 14.多态
- js-Dom节点的获取-以及相关操作
- Blend构建WPF用户界面