题目链接:Find the Multiple

题目大意

找出一个只由0和1组成的能整除n的数。

思路

所有由0和1组成的数可以看作是某个只由0、1组成的数a经过以下两种变化得到

  1、a * 10

  2、a * 10+1

因此只需要用BFS搜索满足条件的数即可。

题解

 #include <iostream>
#include <cstring>
#include <queue> using namespace std; long long n;
int main(int argc, char const *argv[])
{
while(cin >> n && n)
{
queue<long long> q;
q.push();
while(!q.empty())
{
if(q.front() % n == )
{
cout << q.front() << endl;
break;
}
q.push(q.front()*);
q.push(q.front()*+);
q.pop();
}
}
return ;
}

Find the Multiple POJ-1426的更多相关文章

  1. Find The Multiple POJ - 1426 (BFS)

    题目大意 给定一个整数,寻找一个只有0,1构成的十进制数使得这个数能够整除这个整数 解法 直接bfs第一位放入1,之后每一位放入1或者0 代码 #include <iostream> #i ...

  2. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

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

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

  4. POJ 1426 Find The Multiple(寻找倍数)

    POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given ...

  5. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

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

    题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...

  7. POJ 1426 Find The Multiple(数论——中国同余定理)

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

  8. 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 nonzer ...

  9. poj 1426 Find The Multiple( bfs )

    题目:http://poj.org/problem?id=1426 题意:输入一个数,输出这个数的整数 倍,且只有0和1组成 程序里写错了一个数,结果一直MLE.…… #include <ios ...

  10. POJ - 1426 Find The Multiple(搜索+数论)

    转载自:優YoU  http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...

随机推荐

  1. C#ORM中的对象映射

    使用Linq.Expressions来动态生成映射方法 1.我们先写个简单的类Test,包含一个ID和Name. public class Test { public int? ID { get; s ...

  2. vscode 代码补全工具之aiXcoder

    突然发现了一个好用的代码补全工具,与人工智能相关,具有自学习能力,据说用的越久补全效果越好,可以帮助我们节省掉好多敲代码的时间,所以这么好的工具当然要分享给大家了.废话不多说,直接上vscode的安装 ...

  3. 洛谷 P1640 【连续攻击游戏】

    question bank :luogu question Number :1640 title :Continuous attacking game link :https://www.luogu. ...

  4. 2019dx#7

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 A + B = C 10.48%(301/2872)   1002 Bracket Seq ...

  5. HDU - 4305 - Lightning 生成树计数 + 叉积判断三点共线

    HDU - 4305 题意: 比较裸的一道生成树计数问题,构造Krichhoof矩阵,求解行列式即可.但是这道题还有一个限制,就是给定的坐标中,两点连线中不能有其他的点,否则这两点就不能连接.枚举点, ...

  6. Trace 2018徐州icpc网络赛 思维+二分

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...

  7. 牛客多校第十场 A Rikka with Lowbit 线段树

    链接:https://www.nowcoder.com/acm/contest/148/A来源:牛客网 题目描述 Today, Rikka is going to learn how to use B ...

  8. cesium页面小控件的隐藏

    cesium页面小控件的隐藏 1   创建一个Viewer var viewer = new Cesium.Viewer('cesiumContainer');//cesiumContainer为di ...

  9. JAVA - 一个for循环实现99乘法表

    public class Test03 {public static void main(String[] args) { int lie = 1; for (int hang = 1; hang&l ...

  10. PHP 实现字符串表达式计算

    什么是字符串表达式?即,将我们常见的表达式文本写到了字符串中,如:"$age >= 20",$age 的值是动态的整型变量. 什么是字符串表达式计算?即,我们需要一段程序来执 ...