题目链接:http://poj.org/problem?id=1426

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


题解:

题目说答案的位数不会超过100,所以以为是:高精度 + 模运算。这样也太丧心病狂了吧!

后来实在想不到其他方法,就看了题解。结果是一道普通的搜索题,答案用long long存就够了(题目不是说位数<=100),感觉被骗了。

再一次受到了启发:面对一些题目(人生也如此)时,如果想到的方法似乎不能解决问题,但除此之外又无其他办法,那就就要放开手脚试一试,不要畏手畏脚。如果想到的唯一方法都搁置不试,那就相当于交白卷了;试一试,或许能出现意想不到的结果。


代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = +; queue<LL>q;
LL bfs(int n)
{
while(!q.empty()) q.pop();
q.push(); while(!q.empty())
{
LL x = q.front();
q.pop();
if(x%n==)
return x;
q.push(1LL*x*);
q.push(1LL*x*+);
}
} int main()
{
int n;
while(scanf("%d",&n) && n)
{
cout<< bfs(n) <<endl;
}
}

POJ1426 Find The Multiple —— BFS的更多相关文章

  1. poj1426 - Find The Multiple [bfs 记录路径]

    传送门 转:http://blog.csdn.net/wangjian8006/article/details/7460523 (比较好的记录路径方案) #include<iostream> ...

  2. POJ1426——Find The Multiple

    POJ1426--Find The Multiple Description Given a positive integer n, write a program to find out a non ...

  3. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  4. POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)

    http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...

  5. POJ1426Find The Multiple[BFS]

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27433   Accepted: 114 ...

  6. POJ1426 Find The Multiple (宽搜思想)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24768   Accepted: 102 ...

  7. ZOJ 1136 Multiple (BFS)

    Multiple Time Limit: 10 Seconds      Memory Limit: 32768 KB a program that, given a natural number N ...

  8. poj1426 Find The Multiple

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14622   Accepted: 593 ...

  9. POJ 1465 Multiple (BFS,同余定理)

    id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS   Memory Limit: 32768K T ...

随机推荐

  1. Spoj-NPC2015A Eefun Guessing Words

    Eefun Guessing Words Eefun is currently learning to read. His way of learning  is unique, by trying ...

  2. 联合权值(codevs 3728)

    Description 无向连通图 G 有 n 个点,n−1 条边.点从 1 到 n 依次编号,编号为 i 的点的权值为 Wi,每条边的长度均为 1.图上两点 (u,v) 的距离定义为 u 点到 v ...

  3. .net面试题汇总-第二篇

    本篇主要关注下,.net面试题中经常用的算法问题 1.有一群猴子,它们每天要吃桃子,它们第一天吃的数量是总量的一半再多一个,第二天吃的是第一天剩下的一半再多一个,第三天吃的是第二天剩下的一半多一个,以 ...

  4. 洛谷 P1616 疯狂的采药

    传送门  题目描述 Description LiYuxiang是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他 ...

  5. 标准C程序设计七---14

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  6. 开始学习Objective-C

        加油!     顺便试试这MarsEdit好用不~

  7. T2639 约会计划 codevs

    http://codevs.cn/problem/2639/ 题目描述 Description cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而 ...

  8. codevs 2964公共素数因数

    2964 公共素数因数  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 小单同学刚学习了一个数分解成几个素 ...

  9. Windows 10安装IntelliJ IDEA时快捷键冲突设置

    Windows的快捷键的非常多,而且个性化软件获得这些权限的也很多,所以没有最终的方法,只能不断的发现和尝试. 下面是收集的一些教程,或许能在这里找到灵感: 切记:不建议优先修改IDEA的快捷键,应该 ...

  10. Linux下&/jobs/fg/bg命令的使用(转)

    一.& 这个用在一个命令的最后,可以把这个命令放到后台执行. 二.[Ctrl]+[Z] 可以将一个正在前台执行的命令放到后台,并且暂停. 三.jobs 查看当前有多少在后台运行的命令. 四.f ...