- 最小数字倍数
- 2016-11-09 19:33:19 @
rt
2 条评论
-
feidaoluoye LV 9 @ 2016-12-06 18:58:51
为什么一直超时
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxa 19
using namespace std;
int a[maxa],m,b[10000],len,c[10],len1;
bool check()
{
int ok[maxa],i;
memset(ok,0,sizeof(ok));
for(i=0;i<len;++i)
ok[b[i]] =1;
for(i=0;i<10;++i)
if(a[i]==0&&ok[i]==1)
return false;
return true;
}
void add()
{
int i;
for(i=0;i<len1;++i)
b[i]+=c[i];
for(i=0;i<len;++i)
{
b[i+1]+=b[i]/10;
b[i]=b[i]%10;
}
while(b[len]>0)
{
b[len+1]+=b[len]/10;
b[len]%=10;
len++;
}
}
int main()
{
int n,i,x;
scanf("%d",&n);
scanf("%d",&m);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=0;i<m;++i)
{
scanf("%d",&x);
a[x] = 1;
}
int t = n,j;
i = j =0;
while(t>0)
{
b[i++] = t%10;
c[j++] = t%10;
t/=10;
}
len1 = i;
len = i;
while(1)
{
if(check())
{
for(i=len-1;i>=0;--i)
printf("%d",b[i]);
break;
}
add();
}
return 0;
} -
2016-11-09 20:16:01@
oh一个数可以用多次啊。。
- 1