zoukankan      html  css  js  c++  java
  • zzulioj 2570:找子串(尺取)

    练习一下刚刚学习的尺取法

    #include<cstdio>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #define TP 233333333333333
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    const int maxn = 10005;
    char str[maxn];
    int cnt[30];
    bool check() {  //判断是否选取区段是否包含全部26个字母
    	for (int i = 0; i<26; i++)
    		if (!cnt[i] || cnt[i] < 0)
    			return true;
    	return false;
    }
    int main(void) {
    	while(gets(str)) {
    		memset(cnt, 0, 30*sizeof(int));
    		int kase = 0, start = 0, _min = INT_MAX;
    		ll t = TP;
    		while(t--) {
    			while(check()) { //选取一段满足条件的字符串,起始位置为start, 终止位置为kase
    				cnt[str[kase++] - 'A']++;
    				if (kase >= strlen(str))
    					break;
    			}
    			if (check()) //如果该段没有满足条件的字符串直接跳出
    				break;
    			_min = min(_min, kase-start); 
    			cnt[str[start++] - 'A']--; //让左边的起点往右移动一位
    			}
    			if (_min != INT_MAX)
    				cout << _min << endl;
    			else 
    				cout << "NO\n";
    		}
        return 0;
    }
    
  • 相关阅读:
    nginx 学习
    java 数组转字符串(以逗号分隔开)
    索引命名规范
    java常见的设计模式
    java中的堆、栈浅解。
    Oracle忘记System密码怎么办?
    端口被占用,怎么解决?
    Spring Mvc学习之路
    svg了解一下
    推荐几款基于vue的使用插件
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12266527.html
Copyright © 2011-2022 走看看