POJ3320 Jessica's Reading Problem

  set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用

  

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const int MAX_P = ;
int P;
int a[MAX_P];
int main()
{
scanf("%d", &P);
for (int i = ; i < P; ++i)
{
scanf("%d", &a[i]);
}
set <int> all;
for (int i = ; i < P; ++i) {
all.insert(a[i]);
}
int n = all.size();
int s = , t = , num = ;
map<int, int> count;
int res = P;
for (;;)
{
while (t < P && num < n) {
if (count[a[t]]== ) { //出现了新的知识点
num++;
}
count[a[t]]++;
t++;
}
if (num < n) break;
res = min(res, t-s);//更新最小区间长度
count[a[s]]--;
if (count[a[s]] == ) //某个知识点出现次数为0
{
num--;
}
s++;
}
printf("%d\n", res );
return ;
}

POJ3320 Jessica's Reading Problem(尺取+map+set)的更多相关文章

  1. POJ 3320 Jessica's Reading Problem 尺取法/map

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7467   Accept ...

  2. poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)

    这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...

  3. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12346   Accep ...

  4. poj 3320 jessica's Reading PJroblem 尺取法 -map和set的使用

    jessica's Reading PJroblem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9134   Accep ...

  5. poj3320 Jessica's Reading Problem

    Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...

  6. poj3320 Jessica's Reading Problem(尺取思路+STL)

    https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...

  7. 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 ...

  8. POJ3320 Jessica's Reading Problem

    Bryce1010模板 #include <stdio.h> #include <string.h> #include <stdlib.h> #include &l ...

  9. 【二分】Jessica's Reading Problem

    [POJ3320]Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1309 ...

随机推荐

  1. Spfa费用流模板

    ; ,maxm=; ,fir[maxn],nxt[maxm],to[maxm]; int cap[maxm],val[maxm],dis[maxn],path[maxn]; void add(int ...

  2. poj 2408 Apple Tree

    http://poj.org/problem?id=2486 典型的回溯题目:特别是状态方程用三维的来标记是否要走回路. 题意:一颗树,n个点(1-n),n-1条边,每个点上有一个权值,求从1出发,走 ...

  3. linux运维社区站点收集

    1, 新世纪linux社区 offical locator: http://www.21ops.com/industry-news/24370.html 2,

  4. 【行业干货】ASOS:外来快时尚品牌的入华战 - 行业干货 - 京东内部论坛 - Powered by Discuz!

    [行业干货]ASOS:外来快时尚品牌的入华战 - 行业干货 - 京东内部论坛 - Powered by Discuz! [行业干货]ASOS:外来快时尚品牌的入华战

  5. Linux下设置允许myql数据库远程连接

    系统环境: Linux ubuntu --generic #-Ubuntu SMP Thu Apr :: UTC x86_64 x86_64 x86_64 GNU/Linux 系统中已经安装好mysq ...

  6. PHP学习之[第05讲]PHP5.4 循环结构、系统函数和自定义函数

    一.while/for/break/continue: while (expr){ statements } for (expr1:expr2:expr3){ statement } break n  ...

  7. U磁盘检测和大量收集量产工具

    1.ChipGenius ChipGenius是一款USB设备芯片型号检測工具,能够自己主动查询U盘.MP3/MP4.读卡器.移动硬盘等一切USB设备的主控芯片型号.制造商.品牌.并提供相关资料下载地 ...

  8. 统计Oracle数据库文件的大小

    1. 统计数据文件.暂时文件.日志文件大小 select sum(bytes)/1024/1024/1024 as GB from dba_data_files; select sum(bytes)/ ...

  9. Java 理论与实践: 用弱引用堵住内存泄漏---转载

    要让垃圾收集(GC)回收程序不再使用的对象,对象的逻辑 生命周期(应用程序使用它的时间)和对该对象拥有的引用的实际 生命周期必须是相同的.在大多数时候,好的软件工程技术保证这是自动实现的,不用我们对对 ...

  10. 获取context path或者basePath

    转自:http://hexudonghot.blog.163.com/blog/static/532043422012112264411234/ 在jsp中获取context path或者basePa ...