poj3320 Jessica's Reading Problem(尺取思路+STL)
https://vjudge.net/problem/POJ-3320
尺取法,要想好组织方式。
又被卡了cin。。
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
set<int> st;
map<int, int> mp;
int a[];
int main()
{ int n;
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%d", &a[i]);
st.insert(a[i]);
mp[a[i]] = ;
}
int m = st.size();
int s=, t=, num=, ans = INF;
while(){
while(t < n&&num < m){//判断种类是否都涵盖
if(mp[a[t++]]++ == ){//如果是该类知识点的第一个
num++;//种类++
}
}
if(num < m) break;
ans = min(ans, t-s);
if(--mp[a[s++]] == ){//后判断a[s]的类的个数--后是否为0
num--;//种类--
}
}
printf("%d\n", ans);
return ;
}
poj3320 Jessica's Reading Problem(尺取思路+STL)的更多相关文章
- POJ3320 Jessica's Reading Problem(尺取+map+set)
POJ3320 Jessica's Reading Problem set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用 #inc ...
- 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 Problem 尺取法/map
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7467 Accept ...
- poj3320 Jessica's Reading Problem
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- 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 ...
- A - Jessica's Reading Problem POJ - 3320 尺取
A - Jessica's Reading Problem POJ - 3320 Jessica's a very lovely girl wooed by lots of boys. Recentl ...
随机推荐
- java传值和传引用区别
1. 在java中所有的参数都是传值的,引用符号&的传递是C++中才有的:2. 在java传参中,基本类型(byte--short--int--long--float--double--boo ...
- JS onclick跳转
onclick="javascript:window.location.href='URL'" onclick="location='URL'" onclick ...
- Vue小问题汇总
1.element-UI等组件更改默认样式: >>> https://vue-loader-v14.vuejs.org/zh-cn/features/scoped-css.html ...
- windows搭建RocketMQ服务
写在前面: 1.基于rocketmq 4.2.0版本 2.64位 win10 系统 3.JDK 1.8 (注意,jdk路径一定不要有空格,不然执行相应的cmd命令时会报错) 4.其它需要的软件,mav ...
- Python学习(二十四)—— 前端基础之Bookstrap
转载自:http://www.cnblogs.com/liwenzhou/p/8214637.html 一.Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.Jav ...
- Codeforces 1144G Two Merged Sequences dp
Two Merged Sequences 感觉是个垃圾题啊, 为什么过的人这么少.. dp[ i ][ 0 ]表示处理完前 i 个, 第 i 个是递增序列序列里的元素,递减序列的最大值. dp[ i ...
- pyV8不支持dom操作,关于PyV8的支持DOM的疑问
https://www.cnblogs.com/zdz8207/p/python_learn_note_123.html
- LOJ.6068.[2017山东一轮集训Day4]棋盘(费用流zkw)
题目链接 考虑两个\(\#\)之间产生的花费是怎样的.设这之间放了\(k\)个棋子,花费是\(\frac{k(k-1)}{2}\). 在\((r,c)\)处放棋子,行和列会同时产生花费,且花费和该行该 ...
- 2017-9-15-Linux移植:WinSCP软件 & SSH Server开启
在Linux电脑上面安装了TFTP server,但是各种不给力,决定寻找其他办法在Windows和Linux之间传输文件. WinSCP 是一个 Windows 环境下使用 SSH 的开源图形化 S ...
- python基础一 ------linux某目录下批量的为特定文件加入可执行权限
需求: 一个文件夹中有个文件,要求对特定的文件加入可执行权限 某文件系统目录下有一系列文件: quicksort graph.py heap.java install.sh ...