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. pyqt QTableView例子学习

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import  * from Py ...

  2. Maven项目部署方案

    以xbank项目做为应用背景,简单说明一下Maven项目的部署方案: 1.项目说明 xbank基础服务端的11个子项目均采用Maven搭建: 其中各项目功能设计如下: froad-xbank-serv ...

  3. 十分钟学会写shell脚本

    大家好!我是handsomecui,下面我为大家讲解一下shell脚本的写法,讲的不好的地方,欢迎大家留言拍砖. 1.在linux下会写shell脚本是非常重要的,下面我参照例子给大家展示几个脚本,顺 ...

  4. Java动态 遍历List 时删除List特征元素 异常问题 及解决方案总结

    首先.这是一个极其简单的问题,大牛可忽略.新手可能会遇到,Java中遍历某个List 时删除该List元素 会抛出异常. 这一个简单的问题再高手严重不值一提,但新手可能会比較困惑,用哪种方式能够安全有 ...

  5. OLEDB简介

    OLE DB(OLEDB)是微软的战略性的通向不同的数据源的低级应用程序接口.OLE DB不仅包括微软资助的标准数据接口开放数据库连通性(ODBC)的结构化查询语言(SQL)能力,还具有面向其他非SQ ...

  6. 调起qq临时通话

    1.在qq推广的网站上的推广工具中将个人或者公司的qq确认为推广qq 2. 选择好显示的图片,将代码拷贝到页面上就可以了

  7. Linux中oracle的安装,亲测

    一.下载oracle的软件包 地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-li ...

  8. I - u Calculate e

    Description A simple mathematical formula for e is where n is allowed to go to infinity. This can ac ...

  9. cherry-pick,revert和rebase使用的3-way合并策略

    git中的cherry-pick,revert和rebase都使用的是3-way合并策略,下面就来看看这3个方法使用的merge-base,ours和theirs分别是什么. cherry-pick ...

  10. CF 13E Holes 【块状链表】

    题目描述: 一条直线上n个点,每个点有个“弹力”,可以把当前位置x上面的ball弹到x+a[x]上面. 两种操作 0. 修改a处的弹力值,编程b 1. 询问a点的ball经过多少次能跳出n个点外(就是 ...