题目传送门

 /*
题意:找出一个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. 如何爬取可用的IP代理

    上一篇说到对付反爬虫有一个很关键的方法就是使用IP代理,那么我们应该如何获取这些可用的IP代理呢?这里分享一下自己这两天的一些爬取IP代理的心得体会. 1 步骤 1.找到几个提供免费IP代理的网站,获 ...

  2. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  3. Java:PPT(X)转图片、PDF和SVG

    (一) 简介: 工作中,PowerPoint文档有时需要被转换为PDF/图像文件来存档.因为PDF或图片的页面布局是固定的,很难被修改且能被大多数设备打开,所以PDF或者图片比起PowerPoint格 ...

  4. PopupMenu的演示样例

    弹出菜单是停靠在一个View上的一个模式菜单. 假设View对象下方有空间,那么弹出菜单将显示在停靠对象的下方,否则会显示在上方. 这是很实用的: 源代码地址:http://download.csdn ...

  5. Creating A Simple Web Server With Golang

    原文:https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ -------------------- ...

  6. datatables对于某一特定的列进行自定义排序

    首先说下里边的api,其中第一个是order,这个里边是设置哪些排序哪些不排序的,比如:$('#example').dataTable( {     "order": (funct ...

  7. luogu2827 蚯蚓

    题目大意 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」= [3.9」=3. 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓 ...

  8. python安装了2.7之后终端无法使用退格,上下左右

    遇到RT问题,原因是由于在编译python的时候去烧readline库造成的 解决办法: yum install readline-devel 然后重新编译安装python,终端控制符可用!

  9. SQLyog软件里无法插入中文(即由默认的latin1改成UTF8编码格式)

    问题详情: 无法插入中文? 解决办法: 需要修改编码格式,由默认的latin1改为utf8. 改成, 成功!

  10. BZOJ_1115_[POI2009]石子游戏Kam_博弈论

    BZOJ_1115_[POI2009]石子游戏Kam_博弈论 Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子 ...