题目链接:POJ1426
题目数据超水。写了一个普适点的还超时了,写最暴力的还过了,这题没啥意思。
AC代码:
#include<stdio.h>
#include<queue>
#include<string>
#include<string.h>
#include<iostream>
using namespace std;
int n;
const int maxn=220;
char z[]="0";
char o[]="1";
struct node{
char s[maxn];
int m;
};
void bfs(int root){
queue<long long >q;
q.push(1);
while(!q.empty()){
long long cur=q.front();
q.pop();
if(cur%root==0){
printf("%lld\n",cur);
return;
}
q.push(cur*10);
q.push(cur*10+1);
}
}
/*
string :TLE
char: MLE
void bfs(int root){
node a,b;
queue<node> q;
strcpy(a.s,"1");
//a.s="1";
a.m=1%root;
q.push(a);
while(!q.empty()){
node t=q.front();
q.pop();
if(t.m%root==0&&t.m!=0){
cout<<t.s<<endl;
return;
}
strcpy(a.s,t.s);
strcat(a.s,o);
a.m=(t.m%root)*10+1;
q.push(a);
strcpy(b.s,t.s);
strcat(b.s,z);
//b.s=t.s+"0";
b.m=(t.m%root)*10;
q.push(b);
}
}
*/
int main(){
while(scanf("%d",&n)==1&&n){
bfs(n);
}
return 0;
}