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 ...
随机推荐
- mysql中使用update select
UPDATE t_user INNER JOIN t_shake ON t_shake.user_id = t_user.user_id SET t_user.shake_total_num = t_ ...
- delphi调用 java 的 WebService服务端.
// InvRegistry.RegisterInvokeOptions(TypeInfo(ModelADServicePortType), ioLiteral); InvRegistry.Regis ...
- thinkphp操作数据库
1.实现or操作: $where=array( 'city'=>array('like',array('%'.$_GET['city'].'%')); 'hangye'=>array('l ...
- Pandas简易入门(三)
本节主要介绍一下Pandas的数据结构,本文引用的网址:https://www.dataquest.io/mission/146/pandas-internals-series 本文所使用的数据来自于 ...
- Linux进程间通信IPC学习笔记之同步一(线程、互斥锁和条件变量)
基础知识: 测试代码: 参考资料: Posix 多线程程序设计
- javascript面向对象思想2
上篇说到面向对象可以帮我们梳理页面的逻辑的文章(http://www.cnblogs.com/hetaojs/p/6024013.html),很多朋友看了说我这种写法是初级的面向对象小儿科,确实是初级 ...
- Netty多线程处理机制
技术点描述 本文主要研究NioServerSocketChannelFactory类和NioDatagramChannelFactory类, 以及这两个类的各自作用. 由于基于pipelineFact ...
- Indri中的动态文档索引技术
Indri中的动态文档索引技术 戴维 译 摘要: Indri 动态文档索引的实现技术,支持在更新索引的同时处理用户在线查询请求. 文本搜索引擎曾被设计为针对固定的文档集合进行查询,对不少应用来说,这种 ...
- linux编程之线性表
#include"stdio.h" #define MAX 100 typedef struct List{ int length; int num[MAX]; }List_seq ...
- spoj 42
简单题 水水~~ /************************************************************************* > Author: x ...