题目: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 )的更多相关文章

  1. POJ.1426 Find The Multiple (BFS)

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

  2. 题解报告: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 ...

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

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

  4. POJ 1426 Find The Multiple (DFS / BFS)

    题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...

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

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

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

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

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

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

  9. 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 ...

随机推荐

  1. Android 控件收集

    SwipeMenuExpandableListView   https://github.com/tycallen/SwipeMenu-Expandable-ListView

  2. 解决Execwb 导致 ado崩溃的问题。

    http://qc.embarcadero.com/wc/qcmain.aspx?d=61255

  3. oracle通过透明网关连接mysql的配置

    之前配置过连接TD的,这一篇是介绍连接Mysql的配置很详细. http://blog.itpub.net/12679300/viewspace-1177222/

  4. TCP报头

    源端口和目的端口: 各占16位 ,服务相对应的源端口和目的端口. 序列号: 占32位,它的范围在[0~2^32-1],序号随着通信的进行不断的递增,当达到最大值的时候重新回到0在开始递增.TCP是面向 ...

  5. Mac下安装Redis图解教程

    去redis官网(http://redis.io/download)自行下载安装包解压缩到本地文件夹,比如放在Mac应用程序文件夹(/Applications/),在终端进入redis文件夹. 需要进 ...

  6. csu 1303 Decimal (数论题)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1303 1303: Decimal Time Limit: 1 Sec  Memory Limit: ...

  7. mysql 跨库JOIN

    现有两台MYSQL数据库 一台是192.168.1.1 端口3306 上有数据库DB1 有表TABLE1一台是192.168.1.2 端口3307 上有数据库DB2 有表TABLE2192.168.1 ...

  8. @Autowired获取配置文件中被注入实例的两种方式

    一.说明 二.那么在JavaBean中如何通过@Autowired获取该实例呢?有两种方式: 1.直接获取 @RunWith(SpringJUnit4ClassRunner.class) @Conte ...

  9. 【莫比乌斯反演】关于Mobius反演与lcm的一些关系与问题简化(BZOJ 2154 crash的数字表格&&BZOJ 2693 jzptab)

    BZOJ 2154 crash的数字表格 Description 今天的数学课上,Crash小朋友学习了最小公倍数(Least Common Multiple).对于两个正整数a和b,LCM(a, b ...

  10. MVC EF异常-“序列化类型为 XX 的对象时检测到循环引用”

    原因:在EF实体中,两个互为主外键关系的实体类的导航属性相互引用. 解决方法一:删除一个不需要的类的导航属性 方法二:使用DTO模型 方法三:直接返回需要的属性(不能包括相互引用的属性)