HDU 3183 St Table

Source: Internet
Author: User

Test instructions: Removes M characters from a string of length N to minimize the dictionary order of the resulting new string

Idea: Reverse Construction

1#include"bits/stdc++.h"2 using namespacestd;3 Const intMAXN =100010;4 intN;5 CharANS[MAXN];6 intmin[maxn][ -], max[maxn][ -];7 8 //built St table, ANS[MAXN], n is called after read in9 voidMAKERMQ ()Ten { One     intI, J, Len; A      for(i =1; I <= N; ++i) { -min[i][0] = max[i][0] =i; -     } the  -     intp, q; -      for(j =1; (len =1<< j) <= N; ++j) { -          for(i =1; i + Len-1<= N; ++i) { +p = min[i][j-1]; -Q = min[i + (len >>1)][j-1]; +             if(Ans[p] < Ans[q] | | (Ans[p] = = Ans[q] && p <q)) { AMIN[I][J] =p; at             } -             Else { -MIN[I][J] =Q; -             } -  - //p = max[i][j-1]; in //q = max[i + (len >> 1)][j-1]; - //if (ans[p] > Ans[q] | | (Ans[p] = = Ans[q] && p < q)) { to //max[i][j] = p; + //            } - //else { the //max[i][j] = q; * //            } $         }Panax Notoginseng     } - } the  + //the minimum and maximum values for [L, R] are placed in MinValue and MaxValue and do not require initialization of minValue and MaxValue A voidAskintLintRint&Min_pos) the { +     intPow_num, Len, p, Q; -Pow_num =int(Log (R-l +1)/log (2)); $Len =1<<Pow_num; $  -p =Min[l][pow_num]; -Q = Min[r-len +1][pow_num]; the     if(Ans[p] < Ans[q] | | (Ans[p] = = Ans[q] && p <q)) { -Min_pos =p;Wuyi     } the     Else { -Min_pos =Q; Wu     } -  About //p = max[l][pow_num]; $ //q = Max[r-len + 1][pow_num]; - //if (ans[p] > Ans[q] | | (Ans[p] = = Ans[q] && p < q)) { - //maxValue = ans[p]; - //    } A //else { + //maxValue = ans[q]; the //    } - } $ Charres[1010]; the inttot; the intm; the  the intMain () - { in      while(SCANF ("%s%d", ans +1, &m)! =EOF) { thetot =0; then = strlen (ans +1); About makermq (); the         intCNT = n-m; the         intMin_pos; the         intL =1, r = m +1; +          while(cnt--) { - Ask (L, R, Min_pos); theres[tot++] =Ans[min_pos];BayiL = Min_pos +1; the++R; the         } -Res[tot] =' /'; -         intindex =0; the          while(Index <= tot-1&& Res[index] = ='0') { the++index; the         } the         if(Index = =tot) { -printf"0\n"); the             Continue; the         } theprintf"%s\n", Res +index);94     } the}

HDU 3183 St Table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.