Title Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1127
Idea: The ruler method, at first I consider updating the right pointer until I encounter the same character as the pointer pointing to the L, and found that this does not AC. So a change of thinking.
Always update the r pointer until all characters have appeared again, update the answer and left pointer, resulting in a notch, and then update the R pointer.
1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%lld", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (int i = 0; i < (len); i++) the #defineFor (I, A, Len) for (int i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFull (a) memset ((a), 0x7f7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineOnenum (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongULL; +typedef pair<int,int>PII; thetypedef pair<string,int>psi; -typedef PAIR<LL, Ll>PLL; $typedef map<string,int>MSI; thetypedef vector<int>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; - in Const intMAXN =100100; the intascii[ the]; the CharS[MAXN]; About intN; the the intMain () { the //FRead (); + while(~Rs (s)) { - Cls (ASCII); then =strlen (s);Bayi if(N < -) { theprintf"No solution\n"); the Continue; - } - intRET =0x7f7f7f; the intCNT =0; the intL =0, r =1; theascii[s[l]]++; CNT =1; the while(R <N) { - if(Ascii[s[r]] = =0) cnt++; theascii[s[r]]++; the while(CNT = = -) { theret = min (ret, r-l+1);94ascii[s[l]]--; the if(Ascii[s[l]] = =0) cnt--; thel++; the }98r++; About } - if(ret = =0x7f7f7f) printf ("No solution\n");101 Elseprintf"%d\n", ret);102 }103Rt0;104}
[51nod1127] Shortest containing string (ruler)