POJ3320 Jessica's Reading Problem(尺取+map+set)
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's Reading Problem 尺取法/map
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7467 Accept ...
- poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)
这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...
- 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 ...
- poj 3320 jessica's Reading PJroblem 尺取法 -map和set的使用
jessica's Reading PJroblem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9134 Accep ...
- poj3320 Jessica'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(尺取思路+STL)
https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...
- 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 ...
- POJ3320 Jessica's Reading Problem
Bryce1010模板 #include <stdio.h> #include <string.h> #include <stdlib.h> #include &l ...
- 【二分】Jessica's Reading Problem
[POJ3320]Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1309 ...
随机推荐
- WordPress Comment Extra Fields插件‘swfupload.swf’跨站脚本漏洞
漏洞名称: WordPress Comment Extra Fields插件‘swfupload.swf’跨站脚本漏洞 CNNVD编号: CNNVD-201308-027 发布时间: 2013-08- ...
- 【动态规划】HDU 5492 Find a path (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5492 题目大意: 一个N*M的矩阵,一个人从(1,1)走到(N,M),每次只能向下或向右走.求(N+ ...
- Missing Number ——LeetCode
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- 开源的excel读取库libxls在windows下的编译,且支持中文,全网首发
转载请注明出处:http://www.cnblogs.com/superbi/p/5482516.html 到目前为止,网络和官网上并没有关于libxls在windows下支持中文的教程,也没有现成的 ...
- CodeForces 221(div 2)
A 无trick水题... /* * Author: Plumrain * Created Time: 2013-12-24 22:26 * File Name: B.cpp */ #include ...
- 使用atomic一定是线程安全的吗
这个问题很少遇到,但是答案当然不是.atomic在set方法里加了锁,防止了多线程一直去写这个property,造成难以预计的数值.但这也只是读写的锁定.跟线程安全其实还是差一些.看下面. @inte ...
- SEDA工作笔记(一)
摘要 在普遍认知中,软件开发实践是一项充满不确定性的工作,这是由于编码工作占据了其绝大部分的工作,而编码本身就是具有极大不确定性的.同样,计算机科学被视作一门门槛低,基于经验,而无理论意义的纯工程类学 ...
- .mtl文件格式解析
最近在导入下载的.OBJ文件,有时会出现只有模型而没有材质渲染的情况.难道材质要自己一点一点重新赋予?抓狂……我知道.OBJ文件用来存储模型信息,观察第一行代码,可以看到材质库文件为mtllib ## ...
- Lucene 4.x实践1
在Lucene 3.x时代,<Lucene In Action>是一本相当不错的参考书,书中详细介绍了Lucene各种高级使用技术,对于开发者来说非常实用.但是近期Lucene升级到了4. ...
- OpenGL中glPushMatrix和glPopMatrix的原理
glPushMatrix.glPopMatrix操作事实上就相当于栈里的入栈和出栈. 很多人不明确的可能是入的是什么,出的又是什么. 比如你当前的坐标系原点在你电脑屏幕的左上方.如今你调用glPush ...