题目:Find The Multiple

题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数。

思路:nonzero multiple  非零倍数  啊。

   英语弱到爆炸,理解不了题意。。。。。

   STL 在c++过不了,  一直TLE,

   最后只好看了下大神的代码。

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 50005
const double PI = acos(-1.0);
typedef long long LL ;
LL n;
LL cal(LL n){
queue <LL> s;
LL pos = , x;
s.push(pos);
while(){
pos = s.front();
for(LL i = ; i<; i++){
x = pos * + i;
if(x%n == ) return x;
s.push(x);
}
s.pop();
}
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%I64d", &n) && n){
if(n == ) {
printf("%I64d\n", n);
continue;
}
printf("%I64d\n", cal(n));
}
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

BFS 或 同余模定理(poj 1426)的更多相关文章

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

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

  2. POJ 1426 Find The Multiple &amp;&amp; 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21436   Accepted: 877 ...

  3. poj 1426 Find The Multiple ( BFS+同余模定理)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18390   Accepted: 744 ...

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

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

  5. POJ - 1426 暴力枚举+同余模定理 [kuangbin带你飞]专题一

    完全想不到啊,同余模定理没学过啊,想起上学期期末考试我问好多同学'≡'这个符号什么意思,都说不知道,你们不是上了离散可的吗?不过看了别人的解法我现在会了,同余模定理介绍及运用点这里点击打开链接 简单说 ...

  6. poj 1426 Find The Multiple( bfs )

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

  7. POJ.1426 Find The Multiple (BFS)

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

  8. 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer

    题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...

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

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

随机推荐

  1. Linux 服务器的网络配置 - 2. 查看 Linux 服务器的进程

    2. 查看 Linux 服务器的进程 1)ps [主要选项] -a  显示系统中所有进程的信息 -e  显示所有进程的信息 -f  显示进行的所有信息 -l   以长格式显示进程信息 -r  只显示正 ...

  2. mybatis oracle insert 返回新增的主键值

    <insert id="insertVmsTemplatePlayItem" parameterType="VmsTemplatePlayItem"> ...

  3. 62. Divide Two Integers

    Divide Two Integers Divide two integers without using multiplication, division and mod operator. 思路: ...

  4. webview中的页面兼容iphone6和6+

    其实写这篇文章的本不该是我,而应该是开发ios的小伙伴,但作为一个前端,我想我还是有必要做一下记录的! 首先我想说下在iphone6或者6+中webview内嵌套的页面宽度已经不在是320px,而是3 ...

  5. 关于php跨域cookie共享使用方法

    A 服务器所在的域:a1.main.com,A 有应用 main.phpB 服务所在的域:b1.test.com,B 有应用 test.php 1.在 main.php 里设置 cookie 的时候, ...

  6. Hadoop HDFS编程 API入门系列之HDFS_HA(五)

    不多说,直接上代码. 代码 package zhouls.bigdata.myWholeHadoop.HDFS.hdfs3; import java.io.FileInputStream;import ...

  7. Corba概念(GIOP、IIOP、IOR、ORB、IDL)

    CORBA公用对象请求代理(调度)程序体系结构(Common Object Request Broker Architecture),缩写为 CORBA,是对象管理组织(Object Manageme ...

  8. Python Django之路由系统

    1.初识路由系统 路由系统是用户发请求到URL,然后URL根据路由系统重新指向到函数名的一个对应关系 2.创建project和app django-admin startproject mysite ...

  9. codeforces 361 A - Mike and Cellphone

    原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the wa ...

  10. malloc()参数为0的情况

    问题来自于<程序员面试宝典(第三版)>第12.2节问题9(这里不评价<程序员面试宝典>,就题论题): 下面的代码片段输出是什么?为什么? char *ptr; ))==NULL ...