您的位置:首页 > 其它

【DFS】poj 1426 Find The Multiple

2014-05-23 17:23 393 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: