POJ 1426

http://poj.org/problem?id=1426

一道广搜的题目。

题意就是给你一个n,要你求出n的倍数中,只存在0和1的那个数字

所谓的只存在0和1,那么就是某个数的十倍或者十倍+1,而那个最开始的数应该是1。

 1 Memory :5504K G++ runtime:391MS
 2 #include <iostream>
 3 #include <queue>
 4
 5 using namespace std;
 6
 7 int n;
 8
 9 queue <long long >s;
10
11 void bfs(int n)
12 {
13     while(!s.empty())
14         s.pop();
15     s.push(1);
16     while(!s.empty())
17     {
18         long long now;
19         now=s.front();
20         s.pop();
21         if(now%n==0)
22         {
23             cout<<now<<endl;
24             return ;
25         }
26         s.push(now*10);
27         s.push(now*10+1);
28     }
29 }
30
31 int main()
32 {
33     while(cin>>n&&n)
34     {
35         bfs(n);
36     }
37     return 0;
38 }
时间: 2024-10-11 17:37:21

POJ 1426的相关文章

poj 1426 Find The Multiple 搜索进阶-暑假集训

E - Find The Multiple Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only

POJ 1426 &lt;Find The Multiple&gt; &lt;搜索&gt;

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

[题解] [BFS] POJ 1426 - Find The Multiple

p { margin-bottom: 0.25cm; line-height: 115% } a:link { } VJudge题目:https://cn.vjudge.net/contest/279018#problem/L 即POJ 1426 - Find The Multiple:http://poj.org/problem?id=1426 题目要求: 给出一个不大于200的整数n,要求找到任意一个n的倍数(十进制),并且这个倍数只由1与0组成,最多100位. 输入输出:输入以0结束. 示

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 1426 Find The Multiple

POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Accepted: 10613   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representati

DFS/BFS(同余模) POJ 1426 Find The Multiple

题目传送门 1 /* 2 题意:找出一个0和1组成的数字能整除n 3 DFS:200的范围内不会爆long long,DFS水过~ 4 */ 5 /************************************************ 6 Author :Running_Time 7 Created Time :2015-8-2 14:21:51 8 File Name :POJ_1426.cpp 9 ******************************************

20200202 POJ - 3126 Prime Path POJ - 1426 Find The Multiple

>>>>>>>>>POJ 1426直达?? >>>>>>>>>POJ 3126直达?? 做了这么几道搜索题,感觉差不多也摸出了门路,模板差不多记下来了,只是面对不同的题目算法不同罢了 简单写一下想法,搞明白搜索的主题到底是什么(之前的mutiple那题,一开始就没想明白到底搜谁,就没想到算法 TBC(晚上再写 ===================================分割线=======

poj 1426 Find The Multiple (bfs 搜索)

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

Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28550   Accepted: 11828   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 思路,线性同余,搜索 难度:2

http://poj.org/problem?id=1426 测试了一番,从1-200的所有值都有long long下的解,所以可以直接用long long 存储 从1出发,每次向10*s和10*s+1转移,只存储余数即可, 对于余数i,肯定只有第一个余数为i的最有用,只记录这个值即可 #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn=222