POJ - 1426 Find The Multiple(15.10.10 搜索专题)bfs
来源:互联网 发布:淘宝拒收可以退款吗 编辑:程序博客网 时间:2024/06/07 01:01
Find The Multiple
Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u
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
26190
Sample Output
10100100100100100100111111111111111111
题意:求一个数位上只有1或0的十进制数,满足可以被n整除。
思路:打表可以看到n<=200的时候所求数的最高位不会超过long long的范围,直接暴搜还是过不了,加一点剪枝就过了。但还是不理解为什么可以这样剪枝,想明白后再来写。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;#define LL long longbool vis[2001];LL bfs(int n){memset(vis, false, sizeof(vis));queue<LL>que;que.push(1);vis[1] = true;while (!que.empty()){LL loc = que.front();vis[loc%n] = true;que.pop();if (loc%n == 0)return loc;if(!vis[(loc*10)%n]) que.push(loc * 10);if(!vis[(loc*10+1)%n]) que.push(loc * 10 + 1);}return -1;}int main(){int n;while (scanf("%d",&n)!=EOF && n){LL ans = bfs(n);printf("%I64d\n", ans);}}
0 0
- POJ - 1426 Find The Multiple(15.10.10 搜索专题)bfs
- poj 1426 Find The Multiple (bfs 搜索)
- POJ 1426 Find The Multiple (bfs搜索)
- POJ 1426 Find The Multiple (bfs)
- poj 1426 Find The Multiple(bfs)
- POJ 1426 Find The Multiple (BFS)
- POJ.1426 Find The Multiple (BFS)
- POJ 1426 Find The Multiple(bfs)
- POJ 1426 Find The Multiple(简单搜索bfs)
- poj 1426 Find The Multiple(搜索)
- POJ 1426 Find The Multiple(kuangbin带你飞 专题一:简单搜索)
- POJ 1426 Find The Multiple([kuangbin带你飞]专题一 简单搜索 )
- POJ 1426 Find The Multiple bfs
- poj 1426 Find The Multiple(bfs)
- Find The Multiple (poj 1426 bfs)
- poj 1426 Find The Multiple(bfs)
- POJ 1426-Find The Multiple(bfs)
- POJ 1426 Find The Multiple(BFS)
- Javascript获取属性的值以及比较值
- hdoj Conturbatio 5480 (数组模拟+技巧) 好题
- npm 安装 appium 更换源的方式安装
- [每日一答] [20151011] 如何在Python2.7版本中安装pip程序呢?
- docker-registry2(docker-distribution)环境搭建
- POJ - 1426 Find The Multiple(15.10.10 搜索专题)bfs
- Linux内核工程导论——内核为何使用C语言
- android studio导入os库
- HDU 4770 Lights Against Dudely(暴力枚举) 2013杭州现场赛
- OpenCv:Mat矩阵的初始化
- matlab调用mysql
- 互信息 Mutual Information
- python 查询小程序
- yii视频小记