http://acm.hdu.edu.cn/showproblem.php?pid=3183
题意:取m个数字;使得剩下的数最大;
总结:ST(get);预处理出最值nlogn;
鸽巢定理~;剩下的数必然是第一个在[1,m+1],为x;下一个[x+1,m+2].....
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<string>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-16
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=2e5+9;
const int mod=1e9+7;
inline ll read()
{
ll f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9')
{
if(ss=='-')f=-1;ss=getchar();
}
while(ss>='0'&&ss<='9')
{
x=x*10+ss-'0';ss=getchar();
} return f*x;
}
char s[maxn];
int n;
int st[maxn][50];
char ans[maxn];
int min(int x,int y)
{
return s[x]<=s[y]?x:y;
}
void ST()
{
for(int i=0;i<n;i++) st[i][0]=i;
for(int j=1;j<=(int)(log(1.0*n)/log(2.0));j++)
{
for(int i=0;i+(1<<j)-1<n;i++)
{
st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
}
int query(int l,int r)
{
int x=(int)(log(1.0*(r-l+1))/log(2.0));
return min(st[l][x],st[r-(1<<x)+1][x]);
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int m;
while(cin>>s>>m)
{
n=strlen(s);
m=n-m;
ST();
int cnt=0;
int l=0;
while(m--)//选m个小的
{
l=query(l,n-1-m);
ans[cnt++]=s[l++];
}
int p=0;
while(ans[p]=='0') p++;
if(p>=cnt) cout<<0;
for(int i=p;i<cnt;i++)
{
cout<<ans[i];
}
cout<<endl;
}
return 0;
}