POJ1426 Find The Multiple (宽搜思想)

Find The Multiple
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 24768   Accepted: 10201   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

 

题意:求n个一个倍数,但这个数必须是01串

其实就是利用宽搜的思想枚举: 第一个数是1 , 然后下一个就是 10 (1 * 10) , 11( 1 * 10 + 1),再下一个就是 100(10 * 10), 101(10 * 10 + 1),110 (11 * 10),111(11 * 10 + 1) ...然后比较坑的就是只要是n个一个倍数就行,结果不用跟这个样例一样也可以,然后用long long也能过=_=

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <queue>
 5 using namespace std;
 6 typedef long long LL;
 7 void bfs(int n)
 8 {
 9     queue<LL> q;
10     q.push(1);
11     while (!q.empty())
12     {
13         LL temp = q.front();
14         q.pop();
15         if (temp % n == 0)
16         {
17             printf("%lld\n", temp);
18             return;
19         }
20         q.push(temp * 10);
21         q.push(temp * 10 + 1);
22     }
23 }
24 int main()
25 {
26     int n;
27     while (scanf("%d", &n) != EOF && n)
28     {
29         bfs(n);
30     }
31     return 0;
32 }
View Code

 

 

posted @ 2016-03-31 21:03  zhaop  阅读(148)  评论(0编辑  收藏  举报