POJ 1426

来源:互联网 发布:剑三花姐捏脸数据截图 编辑:程序博客网 时间:2024/06/07 23:55

一道BFS题。要从数据的构成考虑

#include <cstdio>#include <iostream>#include <queue>using namespace std;typedef  long long LL;void bfs(int n){    queue<LL> q;    q.push(1);    while(!q.empty()){        if(q.front()%n==0){printf("%lld\n",q.front());return;}        LL top = q.front();        q.pop();        q.push(top*10);        q.push(top*10+1);    }}int main(){    int n;    while(~scanf("%d",&n)&&n){        bfs(n);    }}
0 0
原创粉丝点击