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[100010];
int main()
{
    
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        st.insert(a[i]);
        mp[a[i]] = 0;
    }
    int m = st.size();
    int s=0, t=0, num=0, ans = INF;
    while(1){
        while(t < n&&num < m){//判断种类是否都涵盖
            if(mp[a[t++]]++ == 0){//如果是该类知识点的第一个
                num++;//种类++
            }
        }
        if(num < m) break;
        ans = min(ans, t-s);
        if(--mp[a[s++]] == 0){//后判断a[s]的类的个数--后是否为0
            num--;//种类--
        }
    }
    printf("%d\n", ans); 
    return 0;
}

 

转载于:https://www.cnblogs.com/Surprisezang/p/9019287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值