题目: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. js处理用户输入的银行卡号实现四位一段,并且只能输入数字

    其中ABC是输入框的id.type="tel"可直接呼出数字键盘. <input type="tel" maxlength="24" ...

  2. SQLServer日志无法收缩原因分析及解决

    SQL Server中的事务日志无疑是SQL Server中最重要的部分之一.因为SQL SERVER利用事务日志来确保持久性(Durability)和事务回滚(Rollback).从而还部分确保了事 ...

  3. JDBC中如何获取SUM函数返回的结果

    代码如下: ResultSet rs = stmt.executeQuery("SELECT sum() from...."); int keyValue = -1; if (rs ...

  4. Hadoop HDFS编程 API入门系列之简单综合版本1(四)

    不多说,直接上代码. 代码 package zhouls.bigdata.myWholeHadoop.HDFS.hdfs4; import java.io.IOException; import ja ...

  5. 配置高可用的Hadoop平台

    1.概述 在Hadoop2.x之后的版本,提出了解决单点问题的方案--HA(High Available 高可用).这篇博客阐述如何搭建高可用的HDFS和YARN,执行步骤如下: 创建hadoop用户 ...

  6. delphi Inc函数和Dec函数的用法

    inc自增函数 .inc(i,n)://i,n:integer;n为自增量 相当于i:=i+n: .inc(i)://i:integer; 相当于i:=i+;   dec自减函数 .dec(i,n): ...

  7. WPF 自定义控件

    在实际工作中,面对不同的客户需求,需要让空间显示出不同的效果.当style已经不能足够满足客户需求时,就需要程序猿自己设计自定义控件了. 根据工作经历,LZ做了个关于自定义控件的小Demo,仅供参考. ...

  8. 线程池的使用ExecutorService

    private ExecutorService executorService = Executors.newFixedThreadPool(5); // 引入线程池来管理多线程 private vo ...

  9. 8.12 CSS知识点5

    背景原点 background-origin 设置元素背景图片的原始起始位置,必须保证背景是background-repeat为no-repeat此属性才会生效. 语法: background-ori ...

  10. MFC 实现字符串的移动

    在视类添加一个WM_KeyDown,然后实现函数写上 switch(nChar) {.. CRect rc; GetClientRect(&rc);   int nWidth = rc.Wid ...