51nod 1127 最短的包含字符串(尺取法)
阿新 • • 發佈:2017-11-23
esp -- pre col long .com color 尺取 def
題目:
簡單尺取法
代碼:
#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 namespacestd; typedef long long ll; #define INF 2147483647 string 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 最短的包含字符串(尺取法)