[深度优先搜索] POJ 1426 Find The Multiple
Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 28550 | Accepted: 11828 | Special Judge |
Description
Input
Output
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
Source
#include<stdio.h>
int n,ans[400];
bool found;
void dfs(int mod,int dep)
{
if(found || dep>19) return;
if(mod==0)
{
for(int i=0;i<=dep;++i) printf("%d",ans[i]);
printf("\n");
found=true;
return;
}
ans[dep+1]=1;
dfs((mod*10+1)%n,dep+1); //mod的运算规律,可以这样想:假设X为当前位以前所有的数,那么当前数为X*10+i(i=0/1),对其取n的余数,(X%n*10%n+i%n)%n,递推即可。
ans[dep+1]=0;
dfs((mod*10)%n,dep+1);
}
int main()
{
int i;
while(~scanf("%d",&n))
{
if(n==0) break;
found=false;
ans[0]=1;
dfs(1%n,0);
}
return 0;
}
[深度优先搜索] POJ 1426 Find The Multiple的更多相关文章
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ 1426 Find The Multiple (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
- POJ - 1426 Find The Multiple(搜索+数论)
转载自:優YoU http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...
- POJ 1426 Find the Multiple 思路,线性同余,搜索 难度:2
http://poj.org/problem?id=1426 测试了一番,从1-200的所有值都有long long下的解,所以可以直接用long long 存储 从1出发,每次向10*s和10*s+ ...
- poj 1426 Find The Multiple (bfs 搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18012 Accepted: 729 ...
随机推荐
- 4W1T教程1 如何使用幻灯片
第一步,读取类别为xxXX前五张幻灯片 <!-- 幻灯片循环开始-->{section name=banner loop=$banner} <li data-transition=& ...
- Hibernate(开放源代码的对象关系映射框架)
Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQL语句,自 ...
- 谈谈Memcached与Redis
1. Memcached简介 Memcached是以LiveJurnal旗下Danga Interactive公司的Bard Fitzpatric为首开发的高性能分布式内存缓存服务器.其本质上就是一个 ...
- CSUOJ_1002
/* * Title : A+B(III) * Data : 2016/11/09 * Author : Andrew */ #include <iostream> #include &l ...
- Java学习--内部类(一)
Java学习--内部类(一) 一. 内部类的定义和特点 class Outer{ privite int num = 5; class Inner{ public void Display(){ Sy ...
- tcpdump用法
http://man.linuxde.net/tcpdump http://www.cnblogs.com/yc_sunniwell/archive/2010/07/05/1771563.html
- Keil软件常见的警告和错误含义。——Arvin
1. warning: #767-D: conversion from pointer to smaller integer 解释:将指针转换为较小的整数 影响:可能造成的影响:容易引起数据截断,造 ...
- Android Intent
Intent在Android中的重要性不言而喻.本文主要总结下Intent使用过程中需要注意的一些问题. 1.隐式Intent AndroidManifest.xml声明时<intent-fil ...
- java, mybatis, 调用mysql存储过程
Map<String, Object> bindinfo = new HashMap<String, Object>(); bindinfo.put(&q ...
- web api+递归树型结构
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...