标签:
题意:求一个十进制数,只能有0和1组成,且必须是n的倍数;
广搜啊;
从1开始,每次乘10或者乘10加一,用一个队列执行就好;
AC代码:
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <queue> using namespace std; int n; void bfs() { queue<long long>q; q.push(1); while(!q.empty()) { long long a=q.front(); q.pop(); if((a*10+1)%n==0) { cout<<a*10+1<<endl; return ; } q.push(a*10+1); if((a*10)%n==0) { cout<<a*10<<endl; return ; } q.push(a*10); } return ; } int main() { while(~scanf("%d",&n)&&n) { bfs(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/qioalu/p/4921580.html