zoukankan      html  css  js  c++  java
  • POJ3320 Jessica's Reading Problem

    Bryce1010模板

    这里写图片描述

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <algorithm>
    #include <iostream>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <math.h>
    using namespace std;
    #pragma warning(disable:4996)
    typedef long long LL;
    #define cinInt(a) scanf("%d",&a)
    #define cinInt64(a) scanf("%I64d",&a)
    #define cinDouble(a) scanf("%lf",&a)
    const int INF = 1 << 30;
    void input(int &x)
    {
        char ch = getchar();
        while(ch>'9' || ch<'0')
            ch = getchar();
        x = 0;
        while(ch>='0' && ch<='9')
        {
            x = x * 10 + ch - '0';
            ch = getchar();
        }
    }
    map<int,int> vis;
    int a[10000000+10];
    int main()
    {
        int n,i;
        int cnt = 0;
        while(scanf("%d",&n)!=EOF)
        {
            for(i=0; i<n; ++i)
            {
               input(a[i]);
                if(!vis[a[i]])
                {
                    vis[a[i]]++;
                    cnt++;//知识点的个数
                }
            }
            vis.clear();
            int ans = INF;
            int s=0,t=0,cnt2=0;
            for(;;)
            {
                while(t<n && cnt2<cnt)//一定要找够cnt个知识点才能够跳出循环
                {
                    if(vis[a[t]]==0)
                        cnt2++;
                    vis[a[t++]]++;
                }
                if(cnt2<cnt)
                    break;
                ans = min(ans,t-s);
                vis[a[s]]--;
                if(!vis[a[s++]])//因为区间的缩小,导致知识点的个数减少
                    cnt2--;
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Linux日志清除
    QT vs x64编译
    VC调用QT的UIDLL
    QT UI获得控件ID(HWND)
    安卓黑客工具
    VMware+Windgb+Win7内核驱动调试
    ubuntu 键盘布局修改
    魅族MX3 smart bar处失灵
    把NDK的工具链提取出来单独使用
    arm指令版本
  • 原文地址:https://www.cnblogs.com/bryce1010/p/9386912.html
Copyright © 2011-2022 走看看