poj 1426 Find The Multiple( bfs )
题目:http://poj.org/problem?id=1426
题意:输入一个数,输出这个数的整数 倍,且只有0和1组成
程序里写错了一个数,结果一直MLE.……
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; long long a;
void bfs()
{
queue<long long>q;
int i,j;
long long x=,pos;
q.push(x);
while(!q.empty())
{
pos=q.front();
q.pop();
for(i=; i<; i++)
{
x=pos*+i;
if(x%a==)
{
cout<<x<<endl;
return;
}
q.push(x);
}
}
}
int main()
{
int i,j;
while(cin>>a&&a)
{
if(a==)
{
cout<<""<<endl;
continue;
}
bfs();
}
return ;
}
还 有用同余模定理做的
(a*b)%n = (a%n *b%n)%n
(a+b)%n = (a%n +b%n)%n
地址:http://blog.csdn.net/lyy289065406/article/details/6647917
poj 1426 Find The Multiple( bfs )的更多相关文章
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- 题解报告:poj 1426 Find The Multiple(bfs、dfs)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- POJ 1426 Find The Multiple (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
- POJ - 1426 Find The Multiple(搜索+数论)
转载自:優YoU http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...
- POJ 1426 Find The Multiple(数论——中国同余定理)
题目链接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find ...
- poj 1426 Find The Multiple (简单搜索dfs)
题目: Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal ...
- POJ 1426 Find The Multiple (dfs??!!)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- 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 ...
随机推荐
- python(六)面向对象
1.封装 支持多重继承,但如果不需要的时候最好不要使用,避免出现不必要的bug: 2.继承 3.多态 4.构造函数 5.私有和共有 在属性前写两个下滑线定义就是私有的
- mysql日期时间操作
select curdate(); --获取当前日期 select last_day(curdate()); --获取当月最后一天. select DATE_ADD(curdate(),interva ...
- 大型网站用什么技术比较好,JSP,PHP,ASP.NET
大型网站,我建议要考虑的问题: 首先讨论一下大型网站需要注意和考虑的问题. 数据库海量数据处理:负载量不大的情况下select.delete和update是响应很迅速的,最多加几个索引就可以搞定,但千 ...
- sql新感悟(where 1 = 1)
花了好久把YII框架看完发现一本很不错的书:SQL案例解析(清华大学出版社),看到一些比较有用的东西,感觉应该把他记录下来,看了好多页发现书中一直有 where 1=1,这样的语句,查过发现“wher ...
- 关于javascript的window.onscroll方法
---恢复内容开始--- 今天在学习javascript的过程中被onscroll这个东西堵了一下午.心情极度郁闷. 在高度较大的网页中,我们通常会加一个返回顶部的按钮,方便用户操作. 代码如下: & ...
- Postgresql 技巧
备份 pg_dump -f "F:/dump.sql"<file name> -U postgres<database name> -h 10.38.197 ...
- 纯CSS实现多选组件
mark: http://blog.meathill.com/tech/fe/create-multiple-select-component-with-pure-css.html Demo: 小宝3 ...
- Arcgis 10.1 求面里面所包含的点的平均值
空间链接的作用:将面上的所有点的值加起来取平均值。赋值给面属性。(我们可以定义右击——定义合并规则 连接要素的字段映射参数中指定的合并规则仅适用于连接要素中的属性,且仅适用于多个要素与目标要素匹配 ...
- 四、记一次失败的 CAS 搭建 之 结果总是那么伤(客户端)
==================================================================================================== ...
- UltraEdit 列模式
使用UltraEdit 列模式 1 进入UltraEdit列模式 a) 通过快捷方式 Alt +c b) UltraEdit --> Column Mode