1.The main idea is, to give you a 1000-digit number, you want to delete m for, the result is the most decimal.
Idea: in n bits inside delete m digit, that is to find n-m digit composition the most decimal
So find the smallest number in the interval [0, M] , the corresponding subscript label I
Then find the minimum number in the interval [i+1,m++] , for the Subscript II
Then find the minimum number in the interval [ii+1,m++] ...
This will find the number of n-m. The purpose of this arrangement is to guarantee the order of the numbers taken out.
2 Code:
#include <cstdio> #include <cstring> #include <cmath> #define Min (a) (a) < (b)? A):(B)) using namespace Std;char s[10005];int a[10005];int an[10005];int st[10005][20];int n,m;void make_st ()// The lowest value of the subscript {for (int j=1) is recorded; (1<<J) <=n; J + +) {for (int i=1; (i+ (1<<J)-1) <=n; i++) {if (a[st[i][j-1]]<=a[st[i+ (1<< (j-1))][j-1])//equals equal to two numbers when the smaller st[i][j is removed ]=ST[I][J-1]; Else st[i][j]=st[i+ (1<< (j-1))][j-1]; }}}int Query (int l,int r) {int K=floor (log2 (r-l+1)); int ans; if (a[st[l][k]]<=a[st[r-(1<<k) +1][k]]) ans=st[l][k]; else ans=st[r-(1<<k) +1][k]; return ans;} int main () {while (scanf ("%s%d", S,&m) ==2) {N=strlen (s); for (int i=0; i<n; i++) {a[i+1]= (s[i]-' 0 '); st[i+1][0]=i+1; } make_st (); int t=1; int temp=1; for (int i=m+1; i<=n; i++)//Find N-mThe smallest {t=query (t,i) from [t,i] each time; An[temp++]=a[t++]; } t=1; while (t<temp&&an[t]==0) t++; if (t>=temp) printf ("0\n"); else {for (int i=t; i<temp; i++) printf ("%d", an[i]); printf ("\ n"); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu 3183 a Magic Lamp (give an n-bit number, delete m numbers from it, make the number of the remaining numbers the smallest (order cannot be changed), and then output)