POJ 1426 Find The Multiple([kuangbin带你飞]专题一 简单搜索 )

题目连接:题目

————————题目大意:给你一个数,找出他的倍数,并且只含有1和0的,输出任意一个

解题思路:枚举所有的由1,0组成的数,找出n的倍数

枚举方式1--->1*10,1*10+1;这样每次取队列的首位*10  或者*10+1;



#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
typedef unsigned long long ll;
void f(int n){
	queue<ll> q;
	q.push(1);
	while(!q.empty()){
		ll front=q.front();
		q.pop();
		if(front%n==0){
			printf("%lld\n",front);
			return ;
		}
		q.push(front*10);
		q.push(front*10+1); 
	}
	
}
int main(){
	int n;
	while(scanf("%d",&n)==1&&n){
	f(n);
	
	}

	return 0;
}


posted @ 2016-10-16 14:24  hong-ll  阅读(135)  评论(0编辑  收藏  举报