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. 【转】Postman接口测试之POST、GET请求方法

    转自竹小冉: https://www.cnblogs.com/zhuxr/p/9009708.html 一.基础知识 1.HTTP的五种请求方法:GET, POST ,HEAD,OPTIONS, PU ...

  2. 文字水平居中和垂直居中的CSS

    首先选择一个需要显示文字的选择器,我这里选择的是微信小程序里面的<view>选择器,在其他语言(如html)的选择器里是一样的做法: <view class="btn-it ...

  3. http接口 两种调用http接口的方法

    import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; ...

  4. jboss-as-7.1.1.Final配置Jndi数据源(以mysql为例)

    1.获取mysql驱动,可以从mysql官方网站下载: http://dev.mysql.com/downloads/connector/j/ 2.进入jboss-as-7安装目录下的modules目 ...

  5. poj3009 Curling 2.0 深搜

    PS:以前看到题目这么长就没写下去了.今天做了半天,没做出来.准备看题解,打开了网站都忍住了,最后还是靠自己做出来的.算是一点进步吧. 分析: 题目的意思没明白或者理解有偏差都没办法做题.看样例3和样 ...

  6. Ubuntu16下安装lamp

    1.安装php7 sudo apt-get install php7.0 php7.0-mcrypt 2.安装MySQL sudo apt-get install mysql-server 输入 su ...

  7. ★Java语法(七)——————————循环语句

    package 自我总结; public class 循环语句 { public static void main(String[] args) { // while 循环 // 用法: // whi ...

  8. Java 入门作业

  9. dubbo之多版本

    当一个接口实现,出现不兼容升级时,可以用版本号过渡,版本号不同的服务相互间不引用. 可以按照以下的步骤进行版本迁移: 在低压力时间段,先升级一半提供者为新版本 再将所有消费者升级为新版本 然后将剩下的 ...

  10. tp实现多语言支持测试

    用tp框架实现网页多种语言切换 时间:2016-11-11 浏览次数:1120 编辑:youjiejie   网页如何设计多种语言切换,本文用tp框架实现网页多种语言切换方法结合实例形式较为详细的分析 ...