【题目链接】:http://codeforces.com/contest/779/problem/B
【题意】
问你要删掉几个数字才能让原来的数字能够被10^k整除;
【题解】
/*
数字的长度不大;
让你删掉最小的数字个数
使得这个数字能被10^k整除;
搜索;
枚举哪些数字被删掉了;
bool记录;
最后再全部乘起来;
枚举删掉1个,删掉两个即可、3、4...;
注意前导0只能有一个的情况就好
*/
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 15;
string s;
int po_w[12],k,len,di,num;
bool bo[15];
void dfs(int x, int now)
{
if (now >= num)
{
int nu = 0,t = 0,fir=-1;
rep1(i, 1, len)
if (bo[i])
{
if (fir == -1)
fir = s[i] - '0';
t++;
nu = nu * 10 + s[i] - '0';
}
if (fir == 0 && t > 1) return;
if (nu%di == 0)
{
printf("%d
", num);
exit(0);
}
return;
}
if (x > len)
return;
bo[x] = false;
dfs(x + 1, now + 1);
bo[x] = true;
dfs(x + 1, now);
}
int main()
{
//freopen("F:\rush.txt", "r", stdin);
po_w[0] = 1;
rep1(i, 1, 9)
po_w[i] = po_w[i - 1] * 10;
cin >> s;
len = s.size();
s = ' ' + s;
scanf("%d", &k);
di = po_w[k];
memset(bo, true, sizeof bo);
for (num = 0;num <= len-1;num++)
dfs(1, 0);
return 0;
}