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. 在iOS上present一个半透明的viewController

    UIViewController *viewController = [[UIViewController alloc]init]; UIViewController* controller = se ...

  2. Zookeeper学习记录(一):设计与实现

    概述 Zookeeper是一个分布式的.开源的分布式应用协调服务.它暴露了一组简单的基础原件,分布式应用可以在这些原件之上实现更高级别的服务,如同步.配置维护.群组.和命名.它被设计成容易编程实现的, ...

  3. 虚拟机IOS开发环境搭建教程

    来源:http://www.cnblogs.com/xiaoyaoju/archive/2013/05/21/3091171.html 安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB ...

  4. 使用Xshell连接Ubuntu

    使用Xshell连接Ubuntu Xshell是一个安全终端模拟软件,可以进行远程登录.我使用XShell的主要目的是在Windows环境下登录Linux终端进行编码,非常方便.本文简单介绍下它的使用 ...

  5. 解决jquery和其他库的冲突

    一.jquery在其他库之后导入 (1)jQuery.noConflict();  //将变量的$控制权转交给其他库.          jQuery(function(){             ...

  6. ajax参数中出现空格

    jquery中发起ajax请求时的参数名中不能有空格.如果是get请求参数的中的空格会变成“+”符而在post请求中看不到这种变化,但无论哪种情况都无法与服务接口的参数就行匹配(此时进行调试也不会触发 ...

  7. c#修改本地连接工具 ip地址,dns,网关,子网掩码

    //Form1类后台     #region 加载配置文件中的信息        /// <summary>        /// 加载配置文件中的信息        /// </s ...

  8. 你所不了解的css选择器

    我们目前接触到的选择器:.class   #id  div  ...... 不了解的选择器:a>b   a+b [a~=b] [a|=b]......   一下说举5 6 7 8为css3中的定 ...

  9. Myeclipse中如何修改Tomcat的端口号

    一,使用 Myeclipse 中自带的 tomcat 右键 configure 弹出窗口 在 port Number 中修改 端口号即可: 二,配置的 tomcat 如果用上述的方法,只能打开这样的窗 ...

  10. 用Dockerfile构建docker image

    dockerfile是为快速构建docker image而设计的,当你使用docker build 命令的时候,docker 会读取当前目录下的命名为Dockerfile(首字母大写)的纯文本文件并执 ...