zoukankan      html  css  js  c++  java
  • 51Nod 1127 最短的包含字符串 (尺取法)

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <string>
     4 #include <cstring>
     5 
     6 #define INF 0xfffffff
     7 using namespace std;
     8 const int maxn = 26;
     9 int a[maxn];
    10 
    11 bool is_ok(){
    12     for (int i = 0; i < 26; i++){
    13         if (!a[i])
    14             return false;
    15     }
    16     return true;
    17 }
    18 
    19 int main(){
    20     ios::sync_with_stdio(false);
    21     string s;
    22     cin >> s;
    23     memset(a, 0, sizeof(a));
    24     bool flag = true;
    25     a[s[0] - 'A']++;
    26     int ans = INF;
    27     int l = 0;
    28     for (int i = 1; i < s.length(); i++){
    29         a[s[i] - 'A']++;
    30         while (is_ok())
    31         {
    32             ans = min(ans, i - l + 1);
    33             a[s[l++] - 'A']--;
    34         }
    35     }
    36     if (ans == INF){
    37         cout << "No Solution" << endl;
    38     }
    39     else
    40         cout << ans << endl;
    41     system("pause");
    42     return 0;
    43 }
  • 相关阅读:
    专业英语阅读(二)
    专业英语阅读(一)
    高精度运算
    高精度运算——加减乘除阶乘
    python常见编程面试题汇总
    python线程
    反射
    单例模式
    生成器、迭代器
    python装饰器
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/8722557.html
Copyright © 2011-2022 走看看