poj 1426 Find The Multiple (BFS)

Find The Multiple

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 22121   Accepted: 9081   Special Judge

Description

Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.

Input

The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

Output

For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.

Sample Input

2
6
19
0

Sample Output

10
100100100100100100
111111111111111111

Source

Dhaka 2002
1404010917 1426 Accepted 5048K 407MS G++ 475B 2015-08-20 10:17:35
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int n;
long long bfs(){
   queue<long long >q;
   q.push(1);
   while(1){
       long long temp=q.front();
       q.pop();
       if(temp%n==0)
        return temp;
       q.push(temp*10);
       q.push(temp*10+1);

   }

}

int main(){
   //int t;
   while(scanf("%d",&n)!=EOF){
       if(n==0)
        break;
       printf("%lld\n",bfs());
   }
   return 0;
}
时间: 2024-10-10 14:50:02

poj 1426 Find The Multiple (BFS)的相关文章

POJ - 1426 - Find The Multiple (DFS)

题目传送:Find The Multiple 思路:DFS AC代码: #include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <cctype> #include <string> #include <

POJ 1426 Find The Multiple(寻找倍数)

p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 24.0000pt } span.10 { font-family: "Times New Rom

poj 3009 Curling 2.0 (BFS)

题目大意要求把一个冰壶从起点"2"用最少的步数移动到终点"3" 其中0为移动区域,1为石头区域,冰壶一旦想着某个方向运动就不会停止,也不会改变方向(想想冰壶在冰上滑动),除非冰壶撞到石头1 或者 到达终点 3 冰壶撞到石头后,冰壶会停在石头前面,此时(静止状态)才允许改变冰壶的运动方向,而该块石头会破裂,石头所在的区域由1变为0. 也就是说,冰壶撞到石头后,并不会取代石头的位置. 终点是一个摩擦力很大的区域,冰壶若到达终点3,就会停止在终点的位置不再移动. 要先明确

POJ 1426 Find The Multiple(DFS,BFS)

Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100

POJ 1426 Find The Multiple(数论——中国同余定理)

题目链接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there

POJ 题目1426 Find The Multiple(DFS)

Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19430   Accepted: 7879   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains

POJ 1426 - Find The Multiple - [DP][BFS]

题目链接:http://poj.org/problem?id=1426 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a correspo

【POJ - 3669】Meteor Shower(bfs)

-->Meteor Shower 直接上中文了 Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平面坐标系的原点放牧,打算在群星断其生路前转移至安全地点. 此次共有M (1 ≤ M ≤ 50,000)颗流星来袭,流星i将在时间点Ti (0 ≤ Ti  ≤ 1,000) 袭击点 (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300).每颗流星都将摧毁落点及其相邻四点的区

(简单) POJ 1426 Find The Multiple,BFS+同余。

Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no mo