POJ3320 Jessica's Reading Problem(尺取+map+set)

时间:2022-09-23 21:11:36

  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&&num;39&semi;s Reading Problem 尺取法&sol;map

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

  2. poj3061 Subsequence&amp&semi;&amp&semi;poj3320 Jessica&&num;39&semi;s Reading Problem&lpar;尺取法&rpar;

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

  3. POJ3320 Jessica&&num;39&semi;s Reading Problem 2017-05-25 19&colon;55 38人阅读 评论&lpar;0&rpar; 收藏

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

  4. poj 3320 jessica&&num;39&semi;s Reading PJroblem 尺取法 -map和set的使用

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

  5. poj3320 Jessica&&num;39&semi;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&&num;39&semi;s Reading Problem(尺取思路&plus;STL)

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

  7. POJ 3320 Jessica&&num;39&semi;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&&num;39&semi;s Reading Problem

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

随机推荐

  1. js笔记----&lpar;运动&rpar;分享 隐藏&sol;显示

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  2. sublime2 Ctags 快捷键

    Commands Listing Command Key Binding Alt Binding Mouse Binding rebuild_ctags ctrl+t, ctrl+r     navi ...

  3. HDU&lowbar;1406 完数

    Problem Description 完数的定义:如果一个大于1的正整数的所有因子之和等于它的本身,则称这个数是完数,比如6,28都是完数:6=1+2+3:28=1+2+4+7+14. 本题的任务是 ...

  4. iOS&colon;不同属性声明方式的解析

    代码: /* 属性声明方式说明: ----------------------- 1 @interface ... { id name } @end 这样声明的属性其实可以认为是private属性,因 ...

  5. FPGA开发(1)

    `timescale ns / ns module system_ctrl ( //globol clock input clk, input rst_n, //synced signal outpu ...

  6. ECMA Script 6&lowbar;异步编程之 Promise

    Promise 对象 异步编程 方案,已同步的方式表达异步的代码,解决回调地狱的问题 比传统的解决方案——回调函数和事件——更合理和更强大 是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步 ...

  7. 吴裕雄 13-MySQL UPDATE 查询

    以下是 UPDATE 命令修改 MySQL 数据表数据的通用 SQL 语法:UPDATE table_name SET field1=new-value1, field2=new-value2[WHE ...

  8. Java的&equals;&equals;与equals之辨,简单解释,很清楚

    "=="和equals方法究竟有什么区别? (单独把一个东西说清楚,然后再说清楚另一个,这样,它们的区别自然就出来了,混在一起说,则很难说清楚) ==操作符专门用来比较两个变量的值 ...

  9. HDU 1232 畅通工程(Kruskal)

    畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  10. 免杀加密 前4K程序

    #include "stdafx.h" #include<windows.h> void Decrypt4k(TCHAR *str) { HANDLE hFile = ...