POJ 3320 Jessica's Reading Problem(尺取法)
来源:互联网 发布:php pdo bindvalue 编辑:程序博客网 时间:2024/04/30 03:30
http://poj.org/problem?id=3320
为了避免开一个下标范围过大的数组,可以用set统计不同的数的个数,用map记录某一个数的一些信息。
#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<set>#include<map>#define N 1000005using namespace std;int a[N];int main(){ int n, cnt, s, t, sum, res; scanf("%d", &n); set <int> all; cnt = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); all.insert(a[i]); } s = 0, t = 0, sum = 0; res = n; cnt = all.size(); map <int, int> Count; for (;;) { while (t < n && sum < cnt) { if (Count[a[t]] == 0) { Count[a[t]] = 1; sum++; } else Count[a[t]]++; t++; } if (sum < cnt) break; res = min(res, t - s); if (Count[a[s]] == 1) { Count[a[s]] = 0; sum--; } else Count[a[s]]--; s++; } 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(尺取法)
- 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 (HASH, 尺取法)
- POJ 3320 Jessica's Reading Problem (尺取法)
- Jessica's Reading Problem(POJ No.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 【尺取法+STLmap set】
- android之Androidstudio下查找sha1
- 第4周项目2-太乐了
- 一个简单的例子教你明白XMLHTTPRequest的原理
- 【JavaScript】JavaScript中的checkbox之全选、全不选、反选
- 以前写的数据结构课设
- POJ 3320 Jessica's Reading Problem(尺取法)
- Android Studio 下安卓 jni 开发错误 undefined reference to AndroidBitmap_getInfo
- 组合数模板
- 学习Java JDBC,看这篇就够了
- 异或运算实现两个数的交换
- bzoj 2140: 稳定婚姻 强连通分量
- 安卓 jni 开发错误 UnsatisfiedLinkError: Native method not found
- 1001. A+B Format (20) - C
- 正则表达式的基础知识点