http://poj.org/problem?id=1426
分析:这个“Special Judge”真是深有含义啊,只要最近的倍数就好了嘛。
#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
typedef __int64 LL;
const int NM=205;
int n,vis[NM];
LL BFS(){
queue<LL>q1;
LL t=1,x1,x2;
int mod1,mod2;
memset(vis,0,sizeof(vis));
while(!q1.empty()) q1.pop();
vis[1%n]=1;
q1.push(t);
while(!q1.empty()){
t=q1.front();q1.pop();
if(t%n==0)
return t;
x1=t*10;x2=x1+1;
mod1=x1%n;mod2=x2%n;
if(!vis[mod1]){
q1.push(x1);vis[mod1]=1;
}
if(!vis[mod2]){
q1.push(x2);vis[mod2]=1;
}
}
}
int main()
{
while(scanf("%d",&n) && n)
printf("%I64d\n",BFS());
return 0;
}