51nod 1127 最短的包含字符串(尺取法)
生活随笔
收集整理的這篇文章主要介紹了
51nod 1127 最短的包含字符串(尺取法)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:
簡單尺取法
代碼:
#include <iostream> #include <algorithm> #include <map> #include <vector> #include <set> #include <math.h> #include <queue> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string> using namespace std; typedef long long ll; #define INF 2147483647string s; map <char,int> m;int main() {cin >> s;int len = s.length();int l = 0,r = 0;int num = 0;int ans = 2000000000;while(true){while(num < 26 && r < len){if(m[s[r]] == 0) num++;m[s[r]]++;r++;}if(num < 26) break;while(num == 26 && l < r){if(m[s[l]] == 1) num--;m[s[l]]--;l++;}ans = min(ans,r-l+1);}if(ans == 2000000000) cout << "No Solution" << endl;else cout << ans << endl;return 0; }總結
以上是生活随笔為你收集整理的51nod 1127 最短的包含字符串(尺取法)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51nod 1649 齐头并进 (dji
- 下一篇: 【读书笔记】沉默的大多数