Find The Multiple
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14622   Accepted: 5938   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

10100100100100100100111111111111111111

就是找倍数,bfs 这题 就是宽搜,我打/*号的是深搜的代码 ,但是很慢,也过不了,很容易就RUNTIME去了!

#include<iostream>
#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
stack<int > q;
struct hal{
int x,leave,floor,front; }l[300000];
int visit[300];
int n,re;
bool init(int num,int flag)
{
/*
l[num].x=flag;
if(flag==0)
{ l[num].leave=(l[num>>1].leave*10)%n;
if(visit[l[num].leave])
return false;
visit[l[num].leave]=1;
l[num].floor=l[num>>1].floor+1;
if(l[num].leave==0)
{
re=num;
return true;
}
if(l[num].floor>200)
return false; }
else if(flag==1)
{
l[num].leave=(l[num>>1].leave*10+1)%n;
if(visit[l[num].leave])
return false;
visit[l[num].leave]=1;
l[num].floor=l[num>>1].floor+1;
if(l[num].leave==0)
{
re=num;
return true;
}
if(l[num].floor>200)
return false; }
else if(flag==-1)
{ l[num].leave=1;
l[num].x=-1;
l[num].floor=1;
} if(init(num<<1,0))
return true;
if(init(num<<1|1,1))
return true;
return false;
*/
int t,w,j;
t=w=1;
l[t].x=-1;
l[t].leave=1;
l[t].floor=1;
l[t].front=-1;
while(t<=w)
{
for(j=0;j<=1;j++)
{
l[++w].floor=l[t].floor+1;
l[w].front=t;
l[w].x=j;
if(j==0)
l[w].leave=(l[t].leave*10)%n;
else
l[w].leave=(l[t].leave*10+1)%n; if(visit[l[w].leave])
{
w--;
continue; }
visit[l[w].leave]=1; if(l[w].leave==0)
{
re=w;
return true;
}
if(l[w].floor>200)
{ continue; }
}
t++;
}
return false;
}
bool bfs(int e)
{
while(l[e].x!=-1)
{
q.push(l[e].x);
e=l[e].front;
}
printf("1");
while(!q.empty())
{
printf("%d",q.top());
q.pop();
}
printf("\n");
return true;
}
int main ()
{ while(scanf("%d",&n)!=EOF&&n)
{
memset(visit,0,sizeof(visit));
visit[1]=1;
l[1].leave=-1;
init(1,-1);
//printf("%d",re);
bfs(re);
}
return 0;
}

poj1426 Find The Multiple的更多相关文章

  1. POJ1426——Find The Multiple

    POJ1426--Find The Multiple Description Given a positive integer n, write a program to find out a non ...

  2. POJ1426 Find The Multiple (宽搜思想)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24768   Accepted: 102 ...

  3. poj1426 Find The Multiple(c语言巧解)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36335   Accepted: 151 ...

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

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

  5. POJ1426 Find The Multiple —— BFS

    题目链接:http://poj.org/problem?id=1426 Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Tota ...

  6. poj1426 Find The Multiple (DFS)

    题目: Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41845   Accepted: ...

  7. POJ1426 Find The Multiple 解题报告

    参考:http://www.cnblogs.com/ACShiryu/archive/2011/07/24/2115356.html #include <iostream> #includ ...

  8. poj1426 - Find The Multiple [bfs 记录路径]

    传送门 转:http://blog.csdn.net/wangjian8006/article/details/7460523 (比较好的记录路径方案) #include<iostream> ...

  9. POJ1426——Find The Multiple (简单搜索+取余)

    题意: 给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除. 用DFS是搜索 当前位数字 (除最高位固定为1),因为每一位都只有0或1两种选择,换而言之是一个双入口BFS. ...

随机推荐

  1. fedora 20下安装vim的C++补全插件clang_complete

    1.安装clang yum install clang 2.安装clang_complete插件 git clone https://github.com/Rip-Rip/clang_complete ...

  2. 解决ActiveX Control异常:"没有注册类(异常来自 HRESULT:0x80040154(REGDB_E_CLASSNOTREG))"

    问题背景: 1.我们的程序是用winform调用unity web player 插件来作为播放器在客户端播放动画文件的. 2.播放器是由我们的客户端程序调用的 3.客户端程序默认是以管理员身份启动的 ...

  3. java 去除重复项

    import java.util.Arrays; import java.util.HashSet; import java.util.Set; class Demo20 { public stati ...

  4. Visual Studio 2013 Web开发、新增功能:“Browser Link”

    微软正式发布Visual Studio 2013 RTM版,微软还发布了Visual Studio 2013的最终版本..NET 4.5.1以及Team Foundation Server 2013. ...

  5. django中使用原生sql

    在Django中使用原生Sql主要有以下几种方式: 一:extra:结果集修改器,一种提供额外查询参数的机制 二:raw:执行原始sql并返回模型实例 三:直接执行自定义Sql ( 这种方式完全不依赖 ...

  6. Win7刷新环境变量

    在“我的电脑”->“属性”->“高级”->“环境变量”中增加或修改环境变量后,需重启系统才能使之生效.有没有什么方法可让它即时生效呢? 下面介绍一种方法: 以修改环境变量“PATH” ...

  7. 通过XSLT转换XML

    Hello,every body.又与大家见面了,哈哈.今天我与大家分享一下XSLT,XSL,XML,XPath.因为项目中有些功能用到了XSLT.XML等技术.所以今天好好研究了一下这几个方面的技术 ...

  8. TCP的流量控制(转载)

    1.TCP的滑动窗口 为了提高信道的利用率TCP协议不使用停止等待协议,而是使用连续ARQ协议,意思就是可以连续发出若干个分组然后等待确认,而不是发送一个分组就停止并等待该分组的确认. TCP的两端都 ...

  9. perl6 JSON::Fast模块json解析的使用

    关于JSON: JSON (JavaScript Object Notation)是一种轻量级的数据交换格式,语法简单,各种语言都有相应的库或者模块支持. 因为JSON非常小巧,解析起来又非常简单,我 ...

  10. Reading source code

    software is a system built up of many parts rebuild that decomposition see the patterns in codes is ...