题目传送门

 /*
题意:找出一个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. struts面试题及答案【重要】

    1. 简述 Struts2 的工作流程: ①. 请求发送给 StrutsPrepareAndExecuteFilter ②. StrutsPrepareAndExecuteFilter 判定该请求是否 ...

  2. vim fulerformat的设置

    在vim中设置选项,有注释很容易明白: set laststatus=1 "2总显示最后一个窗口的状态行,1窗口多于一个时显示最后一个窗口的状态行,0不显示最后一个窗口的状态行 fulerf ...

  3. POJ 3468_A Simple Problem with Integers(线段树)

    题意: 给定序列及操作,求区间和. 分析: 线段树,每个节点维护两个数据: 该区间每个元素所加的值 该区间元素和 可以分为"路过"该区间和"完全覆盖"该区间考虑 ...

  4. [bzoj1717][Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组_二分答案

    Milk Patterns 产奶的模式 bzoj-1717 Usaco-2006 Dec 题目大意:给定一个字符串,求最长的至少出现了$k$次的子串长度. 注释:$1\le n\le 2\cdot 1 ...

  5. Spring Boot实现多个数据源教程收集(待实践)

    先收集,后续实践. http://blog.csdn.net/catoop/article/details/50575038 http://blog.csdn.net/neosmith/article ...

  6. Oracle建表提示SQL 错误: ORA-00904: : 标识符无效

    Oracle建表提示: 错误报告:SQL 错误: ORA-00904: : 标识符无效00904. 00000 -  "%s: invalid identifier"*Cause: ...

  7. 在HTML中显示图片时希望如果图片不存在或者无法显示时,能够显示默认图片

    很多时候,在HTML中显示图片时希望如果图片不存在或者无法显示时,能够显示默认图片.可以通过以下方式: <img src="xxx.jpg" onError="th ...

  8. git的配置文件

    转载:https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ Git Config ...

  9. linux网络结构体

    一 链路层: (1)局域网(以太网ethernet): *struct eth_header:以太网头部. (ethernet/eth.c) *struct net_device:每一个网络设备都用这 ...

  10. 谈论javascript闭包

    闭包看似很简单,其实牵扯了很多东西,例如:上下文作用域(事件处理程序).内存占用.局部以及全局变量.回调函数以及编程模式等 首先我们谈论一个问题,为什么需要闭包? 1.var全局定义(全局污染)- 指 ...