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)的更多相关文章
-
POJ 3320 Jessica&#39;s Reading Problem 尺取法/map
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7467 Accept ...
-
poj3061 Subsequence&;&;poj3320 Jessica&#39;s Reading Problem(尺取法)
这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...
-
POJ3320 Jessica&#39;s Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12346 Accep ...
-
poj 3320 jessica&#39;s Reading PJroblem 尺取法 -map和set的使用
jessica's Reading PJroblem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9134 Accep ...
-
poj3320 Jessica&#39;s Reading Problem
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
-
poj3320 Jessica&#39;s Reading Problem(尺取思路+STL)
https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...
-
POJ 3320 Jessica&#39;s Reading Problem 尺取法
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
-
POJ3320 Jessica's Reading Problem
Bryce1010模板 #include <stdio.h> #include <string.h> #include <stdlib.h> #include &l ...
-
【二分】Jessica&#39;s Reading Problem
[POJ3320]Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1309 ...
随机推荐
-
js笔记----(运动)分享 隐藏/显示
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
-
sublime2 Ctags 快捷键
Commands Listing Command Key Binding Alt Binding Mouse Binding rebuild_ctags ctrl+t, ctrl+r navi ...
-
HDU_1406 完数
Problem Description 完数的定义:如果一个大于1的正整数的所有因子之和等于它的本身,则称这个数是完数,比如6,28都是完数:6=1+2+3:28=1+2+4+7+14. 本题的任务是 ...
-
iOS:不同属性声明方式的解析
代码: /* 属性声明方式说明: ----------------------- 1 @interface ... { id name } @end 这样声明的属性其实可以认为是private属性,因 ...
-
FPGA开发(1)
`timescale ns / ns module system_ctrl ( //globol clock input clk, input rst_n, //synced signal outpu ...
-
ECMA Script 6_异步编程之 Promise
Promise 对象 异步编程 方案,已同步的方式表达异步的代码,解决回调地狱的问题 比传统的解决方案——回调函数和事件——更合理和更强大 是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步 ...
-
吴裕雄 13-MySQL UPDATE 查询
以下是 UPDATE 命令修改 MySQL 数据表数据的通用 SQL 语法:UPDATE table_name SET field1=new-value1, field2=new-value2[WHE ...
-
Java的==与equals之辨,简单解释,很清楚
"=="和equals方法究竟有什么区别? (单独把一个东西说清楚,然后再说清楚另一个,这样,它们的区别自然就出来了,混在一起说,则很难说清楚) ==操作符专门用来比较两个变量的值 ...
-
HDU 1232 畅通工程(Kruskal)
畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
-
免杀加密 前4K程序
#include "stdafx.h" #include<windows.h> void Decrypt4k(TCHAR *str) { HANDLE hFile = ...