POJ1426 BFS

BFS水过去,但是还得用到__int 否则就纠结了。

#include<iostream>

using namespace std;
const int N=200,M=100;
int n;
__int64 que[9999999];
void bfs()
{
int head=1,tail=1;
que[tail++]=1;
while(head<tail)
{
__int64 now=que[head++];
if(now%n==0)
{
printf("%I64d\n",now);
return;
}
que[tail++]=now*10;
que[tail++]=now*10+1;
}
}
int main()
{
//freopen("C:\\Users\\wuyanyisb\\Desktop\\1.txt","r",stdin);
while(scanf("%d\n",&n),n!=0)
{
bfs();
}
system("pause");
return 0;
}
posted on 2011-07-19 22:01  不是我干的  阅读(130)  评论(0)    收藏  举报