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 ...
随机推荐
- ajaxFileUpload - Post file and data together
jQuery.extend({ createUploadIframe: function(id, uri) { //create frame var frameId = 'jUploadFrame' ...
- spring-cloud-hystrix熔断
依赖pom <dependencyManagement> <dependencies> <dependency> <groupId>org.spring ...
- Catalyst揭秘 Day5 optimizer解析
Catalyst揭秘 Day5 optimizer解析 Optimizer是目前为止中catalyst中最重要的部分.主要作用是把analyzed logicalPlan变成optimized Log ...
- Programming Collective Intelligence
最近正在拜读 O'reilly出版的Programming Collective Intelligence,准备研究研究搜索引擎了,童鞋们,到时候会考虑公布源码哦!
- 2015-4-2的阿里巴巴笔试题:乱序的序列保序输出(bit数组实现hash)
分布式系统中的RPC请求经常出现乱序的情况.写一个算法来将一个乱序的序列保序输出.例如,假设起始序号是1,对于(1, 2, 5, 8, 10, 4, 3, 6, 9, 7)这个序列,输出是:123, ...
- 研读代码必须掌握的Eclipse快捷键
1. Ctrl+左键 和F3 这个是大多数人经常用到的,用来查看变量.方法.类的定义跳到光标所在标识符的定义代码.当按执行流程阅读时,F3实现了大部分导航动作. 2 Ctrl+Shift+G在工作空间 ...
- 【BZOJ 1070】[SCOI2007]修车
Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使 ...
- To get TaskID's Integer ID value from the GUID in SharePoint workflow
list.GetItemByUniqueId(guid).ID int itemID = spList.Items[new Guid("")].ID;
- Sql之表的连接总结
1.交叉连接(就是将两张表的数据 交叉组合在一起) 有两张表 客户表:[Sales.Customers] 和订单表:[Sales.Orders]. 业务需求:实现 Customer中custid(客户 ...
- Begin Andriod -- 安装android开发环境
很久以前学过Andriod,现在已经忘的快没有了,重新捡起来练练,顺带写写博客,感受下写博的乐趣. 第一步:安装java jdk.jre(jdk:开发环境,jre:运行环境). (一)java jdk ...