BFS/poj 1426 Find The Multiple

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 using namespace std;
 5 int n;
 6 bool v[210];
 7 unsigned long long bfs(int n)
 8 {
 9     memset(v,0,sizeof(v));
10     queue<unsigned long long>que;
11     unsigned long long now,next;
12
13     now=1;v[1%n]=1;
14     que.push(now);
15
16     while (!que.empty())
17     {
18         now=que.front();
19         if (now%n==0) break;
20         que.pop();
21
22         next=now*10;
23         if (!v[next%n])
24         {
25             v[next%n]=1;
26             que.push(next);
27         }
28
29         next=now*10+1;
30         if (!v[next%n])
31         {
32             v[next%n]=1;
33             que.push(next);
34         }
35
36     }
37     return now;
38 }
39 int main()
40 {
41     scanf("%d",&n);
42     while (n!=0)
43     {
44         printf("%lld\n",bfs(n));
45         scanf("%d",&n);
46     }
47     return 0;
48 }
时间: 2024-11-10 21:41:56

BFS/poj 1426 Find The Multiple的相关文章

[题解] [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结束. 示

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 ******************************************

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

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

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

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 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 (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

(简单) 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