题目传送门

 /*
题意:找出一个0和1组成的数字能整除n
DFS:200的范围内不会爆long long,DFS水过~
*/
/************************************************
Author :Running_Time
Created Time :2015-8-2 14:21:51
File Name :POJ_1426.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; typedef long long ll;
const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
ll n;
bool ok; void DFS(ll x, int step, int dep) {
if (ok) return ;
if (step >= dep) return ;
if (x % n == ) {
printf ("%I64d\n", x);
ok = true; return ;
}
DFS (x * , step + , dep);
DFS (x * + , step + , dep);
} int main(void) { //POJ 1426 Find The Multiple
while (scanf ("%I64d", &n) == ) {
if (!n) break;
ok = false; ll dep = ;
while (true) {
if (ok) break;
DFS (, , dep); dep++;
}
} return ;
}

 /*
BFS+同余模定理:mod数组保存,每一位的余数,当前的数字由少一位的数字递推,
比如4(100)可以从2(10)递推出,网上的代码太吊,膜拜之
详细解释:http://blog.csdn.net/lyy289065406/article/details/6647917
*/
/************************************************
Author :Running_Time
Created Time :2015-8-2 15:14:33
File Name :POJ_1426_BFS.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int mod[MAXN];
int ans[MAXN]; int main(void) {
int n;
while (scanf ("%d", &n) == ) {
if (!n) break;
mod[] = ; int i;
for (i=; mod[i-]; ++i) {
mod[i] = (mod[i/] * + (i&)) % n; //BFS双入口模拟
}
int t = ; i--;
while (i) {
ans[++t] = i & ;
i /= ;
}
while (t) {
printf ("%d", ans[t--]);
}
puts ("");
} return ;
}

BFS

DFS/BFS(同余模) POJ 1426 Find The Multiple的更多相关文章

  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 (BFS)

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

  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

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

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

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

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

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

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

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

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

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

随机推荐

  1. 主席树初探--BZOJ1901: Zju2112 Dynamic Rankings

    n<=10000的序列做m<=10000个操作:单点修改,查区间第k小. 所谓的主席树也就是一个值域线段树嘛..不过在这里还是%%fotile 需要做一个区间查询,由于查第k小,需要一些能 ...

  2. JVM 总结

    面试 java 虚拟机 jvm 基础 jvm Write Once Run EveryWhere >jar 包可以在任何兼容jvm上运行 >jvm 适配器 屏蔽掉底层差异 >内存管理 ...

  3. BootStrap3栅格系统与布局

    栅格系统与布局 Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks t ...

  4. 解析excel文件并将数据导入到数据库中

    今天领导给安排了一个临时工作,让我将一个excel里面的数据解析后放入数据库中,经过一个下午的努力成功完成,现在将代码献上,希望对大家有所帮助 一.需要导入的jar 1.commons-collect ...

  5. Moravec算子

    Moravec在1981年提出了Moravec角点检測算子,并将它应用于立体匹配.它是一种基于灰度方差的角点检測方法.该算子计算图像中某个像素点沿着水平.垂直.对角线.反对角线四个方向的灰度方差,当中 ...

  6. UVA 567 Risk【floyd】

    题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=508">https://uva ...

  7. Android 4.2 project导入 5.0 SDK Eclipse 开发环境出现的问题总结

    Android 4.2 project导入 5.0 SDK Eclipse 开发环境出现的问题总结 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循&qu ...

  8. php高效获取数据分页

    mysql.php 获取数据库中的记录,全然个人经验总结,仅供參考! <? php /** *PHP+MYSQL数据库基本功能 *http://blog.csdn.net/yown */ ### ...

  9. mysql查看所有存储过程,函数,视图,触发器,表

    查询数据库中的存储过程和函数 方法一: select `name` from mysql.proc where db = 'your_db_name' and `type` = 'PROCEDURE' ...

  10. HDU4267 树状数组 不连续区间修改(三维)

    A Simple Problem with Integers                                  Problem Description Let A1, A2, ... ...