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 ...
随机推荐
- Visual Studio 中使用万能头文件 #include <bits/stdc++.h>
最近开始使用VS,之前用的DEV C++软件可直接使用 #include <bits/stdc++.h> ,但VS中并没有,为了使用方便,可直接在VS中添加此头文件,方法如下: 1.在安 ...
- python全栈开发day59-Django基础
一.今日内容总结 1.HTTP协议: 请求:浏览器发给服务端的消息 格式: 请求方法 URL 协议版本\r\n k1: v1\r\n k2: v2\r\n \r\n 请求体(请求数据) 响应:服务端返 ...
- HDU2732 Leapin' Lizards 网络流 最大流 SAP
原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...
- 空间分析工具:GIS
1.数据空间 数据空间是指用来表示空间实体的的位置.几何特征及其属性特征的数据. 位置:经纬度.地址.相对位置: 几何特征:点.线.面.形状: 属性特征:面积.周长.人口.经济等属性. POI数据.O ...
- 12306登录爬虫 cookies版本
import requests import re import base64 cookies = None # 进入主页,保留cookies login_url = 'https://kyfw.12 ...
- 基于Fragment的插件化
--<摘自android插件化开发指南> 1.有些项目,整个app只有一个Activity,切换页面全靠Fragment,盛行过一时,但有点极端 2.Activity切换fragment页 ...
- P2280 [HNOI2003]激光炸弹(二维前缀和)
题目描述 一种新型的激光炸弹,可以摧毁一个边长为R的正方形内的所有的目标.现在地图上有n(n≤10000)个目标,用整数xi,yi(0≤xi,yi≤5000)表示目标在地图上的位置,每个目标都有一个价 ...
- win10安装Oracle11g,出现INS-13001环境不满足最低要求问题
今天安装Oracle11g,出现INS-13001环境不满足最低要求问题: 解决方法 在安装时点击setup.exe之后,出现了:[INS-13001]环境不满足最低要求 这时,打开你的解压后的dat ...
- bootstrap页面sidebar
function change_active(select_item){ $('.mail-navigation').find('li').each(function(){ $(this).remov ...
- 数据库相关--mysql8.0设置root登录密码
系统:win7 64位 MySQL 8.0 .11 1.启动服务: $ net start mysql 进入MySQL(mysql -hlocalhost -uroot): 2.选择mysql ...