POJ 3320 Jessica's Reading Problem
来源:互联网 发布:java telnet vt 编辑:程序博客网 时间:2024/06/10 18:55
白皮书尺取法例题,基本和之前一道题目思路相同。刚开始为了图省事,为中间枚举的数组也开了一个set,但是后来发现会wa,换成hash(map)之后就很好过了。
#include <iostream>#include <cstdio>#include <set>#include <map>#include <algorithm>using namespace std;int a[1000010], p;int main(){scanf("%d", &p);set<int> total, cur;map<int, int> cnt;for (int i = 0; i < p; i++){scanf("%d", &a[i]);total.insert(a[i]);}int size = total.size();int s = 0, t = 0, res = p, sum = 0;for(;;){while (t < p && sum < size){if (cnt[a[t++]]++ == 0)sum++;}if (sum < size)break;res = min(res, t - s);if (--cnt[a[s++]] == 0){sum--;}}printf("%d\n", res);}
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
- T-SQL查询——嵌套子查询
- Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)
- PHP学习笔记(11)—— 递归
- JSP中取bean属性访问不到的问题解决方法
- 笔试怎么过(4)C#笔试和设计模式
- POJ 3320 Jessica's Reading Problem
- eclipse环境安装&Robotium自动化测试环境安装&RobotiumRecord自动化录制环境安装
- 我的cocos2d-x-3.2集成云风pbc lua binding方法
- {Effective Java} Quick Guide
- Codeforces Round #326 Duff in the Army(主席树+LCA)
- 请教SQLITE如何删除表内重复的记录
- 神奇的卷积神经网络(三)
- 有效使用Django的QuerySets
- Tsung安装