Find The Multiple
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18527   Accepted: 7490   Special Judge

Description

Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding
m containing no more than 100 decimal digits.

Input

The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

Output

For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any
one of them is acceptable.

Sample Input

2
6
19
0

Sample Output

10
100100100100100100
111111111111111111

在广搜的题中看到这一个,表示根本想不到广搜,,,,,

每一位仅仅能是0或1,那么求n的倍数。从第一位開始搜。一直找到为止。

第一位一定是1,然后存余数temp,假设下一位是1。那么(temp*10+1)%n得到新的余数。假设是0,那么(temp*10)%n得到余数。这样进行广搜。大小是2^100

剪枝的方法:对于每个求的余数,最多有200个,每个仅仅要出现过一次就好了,出现多的减掉

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
struct node{
int k , temp ;
int last ;
}p[1000000] , q ;
int flag[210] , a[120] , n ;
int bfs()
{
int low = 0 , high = 0 ;
p[high].k = 1 ;
p[high].temp = p[high].k % n ;
flag[p[high].temp] = 1 ;
p[high++].last = -1 ;
while( low < high )
{
q = p[low++] ;
if( q.temp == 0 )
return low-1 ;
if( !flag[ (q.temp*10+1)%n ] )
{
p[high].k = 1 ;
p[high].temp = (q.temp*10+1)%n;
flag[ p[high].temp ] = 1 ;
p[high++].last = low-1 ;
}
if( !flag[ (q.temp*10)%n ] )
{
p[high].k = 0 ;
p[high].temp = (q.temp*10)%n ;
flag[ p[high].temp ] = 1 ;
p[high++].last = low-1 ;
}
}
return -1 ;
}
int main()
{
int i , j ;
while(scanf("%d", &n) && n)
{
memset(flag,0,sizeof(flag));
i = 0 ;
j = bfs();
while( j != -1 )
{
a[i++] = p[j].k ;
j = p[j].last ;
}
for(j = i-1 ; j >= 0 ; j--)
printf("%d", a[j]);
printf("\n");
}
return 0;
}

poj1426--Find The Multiple(广搜,智商题)的更多相关文章

  1. POJ3984 BFS广搜--入门题

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20816   Accepted: 12193 Descriptio ...

  2. POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)

    http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...

  3. poj 1184 广搜进阶题

    起初的想法果然就是一个6000000的状态的表示. 但是后面觉得还是太过于幼稚了. 可以看看网上的解释,其实就是先转换位置,然后再改变数字的大小. #include<iostream> # ...

  4. hdu 1180(广搜好题)

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Subm ...

  5. hdu 2612:Find a way(经典BFS广搜题)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  7. hdu 1253:胜利大逃亡(基础广搜BFS)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. Eight_pku_1077(广搜).java

    Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21718   Accepted: 9611   Special ...

  9. HDU 2267 How Many People Can Survive(广搜,简单)

    题目 //一道简单的广搜水题 #include<queue> #include<stdio.h> #include<string.h> #include<al ...

随机推荐

  1. php处理类

    Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...

  2. JVM内存模型和GC垃圾回收

    JVM 内存区域 1.程序计数器 这是一块较小的内存空间,它的作用可以看做是当前线程所执行的字节码的行号指示器,指的是上次代码被执行的地方,线程私有. 2.Java 虚拟机栈 它是 Java方法执行的 ...

  3. B - Double Cola

    Problem description Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double C ...

  4. MyEclipse加入jquery.js文件missing semicolon的错误

    今天打开项目,发现有一个小红叉,虽然不影响项目的编译和运行,但是看着非常影响心情.原因是jquery-1.8.2.min.js报了一堆missing semicolon的错误.之所以会这样,其实是My ...

  5. Windows下VS2013 C++编译测试faster-rcnn

    [原创帖!转载请注明出处:http://www.cnblogs.com/LaplaceAkuir/p/6445189.html] 本人最近研究faster-rcnn,在ubuntu成功跑通matlab ...

  6. (转)基于Metronic的Bootstrap开发框架经验总结(7)--数据的导入、导出及附件的查看处理

    http://www.cnblogs.com/wuhuacong/p/4777720.html 在很多系统模块里面,我们可能都需要进行一定的数据交换处理,也就是数据的导入或者导出操作,这样的批量处理能 ...

  7. JSP状态管理_1_Cookie

    http协议的无状态性:当浏览器发送请求飞服务器时,服务器相应客户端请求:但当同一个浏览器再次发送请求给浏览器时,服务器并不知道它就是刚才那个客户端. 保存用户状态的两大机制:Session,Cook ...

  8. 范畴论-一个单子(Monad)说白了不过就是自函子范畴上的一个幺半群而已

    范畴即为结构:包含要素和转化. 范畴为高阶类型. 函子为高阶函数.函子的输入为态射.函子为建立在态射基础上的高阶函数.函子用于保持范畴间映射的结构.态射用于范畴内部的转换. 群为运算规则的约束. 自函 ...

  9. day006 数字类型和字符串类型的内置方法

    首先,为什么要有数据类型? 对于不同类型的变量,需要用不同的数据类型去描述. 数字类型的内置方法 数据类型又分为整形和浮点型.以下所述的内置方法均适用于这两个类型. 必须掌握的方法*** 数据类型有基 ...

  10. day004 与用户交互、格式化输出、基本运算符

    目录 今天Python所学习的知识如下:①与用户的交互.格式化输出.基本运算符.以下整理汇总下所学习的知识点. 与用户的交互 input 注意事项: input函数接受的都是字符串 python2中的 ...