您的位置:首页 > 其它

POJ 1426/ ZOJ 1530 Find The Multiple

2013-04-05 17:26 369 查看
直接用BFS打表了,STL的queue速度比较慢,198和99串比较长就手动了,蛋疼

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn=201;
long long table[201];
int n;

void init(){
for (int i=1;i<maxn;++i)
{
if(i==198){
table[i]=1111111111111111110;
continue;
}
if(i==99){
table[i]=111111111111111111;
continue;
}
queue<long long>q;
q.push(1);
while (q.size())
{
long long t=q.front();
q.pop();
if(t%i==0){
table[i]=t;
break;
}
q.push(t*10);
q.push(t*10+1);
}
}
}
int main(){
init();
while (scanf("%d",&n)&&n)
{
printf("%lld\n",table
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: