题目链接: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. ORA-01940: cannot drop a user that is currently connected 问题解析

    https://www.linuxidc.com/Linux/2012-12/76448.htm

  2. Louvain algorithm for community detection

    主要理解Louvain 算法中对于模块度的定义:模块度是评估一个社区网络划分好坏的度量方法,它的物理含义是社区内节点的连边数与随机情况下的边数只差,它的取值范围是 [−1/2,1).可以简单地理解为社 ...

  3. Hadoop安装和基本单机部署

    下载安装  # 下载 $ cd /usr/local $ wget http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop-2.9.2/hadoo ...

  4. Java代码规范和质量检查插件-Checkstyle(官方资源)

    其实Checkstyle是一个JAR包,然后第三方开发者开发了Eclipse/IDEA的插件. 官网: https://github.com/checkstyle/checkstyle Eclipse ...

  5. [转] java中volatile关键字的含义

    在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  6. [转] windows下Svn服务器之必须提交修改注释篇

    1. 强制添加注释信息 找到Respositories目录下对应项目里的hooks目录下建立pre-commit.bat文件,复制如下内容: @echo off set SVNLOOK="C ...

  7. Deleting array elements in JavaScript - delete vs splice

    javascript 数组中删除元素用 array.splice(start, deleteCount);这个方法. ----------------------------------------- ...

  8. 关于HTML中文乱码问题

    系统:ubuntu 14.04 软件:bluefish 一.乱码原因 1.不同编码内容混杂:HTML乱码是因为html编码问题照成(常见gb2312与utf-8两种编码内容同一时候存在照成) 2.未设 ...

  9. 用Meta 取消流量器缓存方便调试

    <!-- 禁止浏览器从本地缓存中调阅页面.--> <meta http-equiv="pragram" content="no-cache"& ...

  10. 仿htc sense的弹性listView!

    demo下载:http://pan.baidu.com/s/1ntoICdV 前一段时间换了htc m7之后,对htc的sense ui有不错的印象.特别是它的listview十分有个性.提供弹性的o ...