http://poj.org/problem?id=1426

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

大致题意:

给出一个整数n,(1 <= n <= 200)。求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成。

没看见是Special Judge
题解:
我感觉这题能够是投机取巧,输出结果根本就没有100位,之前以为是大数,一直没敢做,谁知是一个超级大坑题。
还有给的测试数据给的那么大,害我一看测试数据就不敢做了。还有为什么我用STL中的queue用C++交超时,而用G++就A了
,而自己写的结构体用C++交就过了。
主要思想:
和二叉树差不多,1->10,11;10->100,101,11->110,111.....
就是q.push(t*10);q.push(t*10+1);
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n;
struct node
{
long long int x;
} q[];
struct node t,f;
void bfs()
{
int s=;
int e=;
t.x=;
q[e++]=t;
while(s<e)
{
t=q[s++];
if(t.x%n==)
{
printf("%lld\n",t.x);
break;
}
f.x=t.x*;
q[e++]=f;
f.x=t.x*+;
q[e++]=f;
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n!=)
{
bfs();
}
return ;
}

G++;

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
using namespace std;
int n;
long long t;
void bfs()
{
queue<long long >q;
q.push();
while(!q.empty())
{
t=q.front();
q.pop();
if(t%n==)
{
printf("%lld\n",t);
break;
}
q.push(t*);
q.push(t*+);
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n!=)
{
bfs();
}
return ;
}

POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)的更多相关文章

  1. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  2. hdu1240 bfs 水题

    原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...

  3. Yet Another Multiple Problem(bfs好题)

    Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other)   Memory Limit : 65536/65536K ( ...

  4. nyoj--523--亡命逃窜(BFS水题)

    亡命逃窜 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...

  5. POJ3287(BFS水题)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  6. POJ 3126 Prime Path bfs, 水题 难度:0

    题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...

  7. codeforces 811 D. Vladik and Favorite Game(bfs水题)

    题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子, ...

  8. (简单) POJ 1426 Find The Multiple,BFS+同余。

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

  9. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

随机推荐

  1. django进阶-1

    前言: 各位久等了,django进阶篇来了. 一.get与post 接口规范: url不能写动词,只能写名词 django默认只支持两种方式: get, post get是获取数据 ?user=zcl ...

  2. 【贪心】PAT 1033. To Fill or Not to Fill (25)

    1033. To Fill or Not to Fill (25) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ZHANG, Gu ...

  3. css笔记 - 张鑫旭css课程笔记之 relative 篇

    relative地址 relative 对 absolute的限制作用 限制left/top/right/bottom(方位值)定位 限制描述:absolute设置了方位值时,这些方位值是相对于pos ...

  4. sencha touch 2.3.1 list emptyText不显示

    如图所示,有时候没有取到任何的数据. 那么我们就需要显示没有获取到内容这一类提示,显示内容通常通过emptyText这个属性来配置. 但是在sencha touch 2.3.1之中有可能会出问题,所以 ...

  5. html中相关知识点的汇总

    1. Input的size与maxlength属性的区别 maxlength="500",表示input输入框中最多够输入500个字符.W3C标准指出maxlength规定文本字段 ...

  6. sort与asort与ksort区别

    sort只依据值从小到大排序,键值不参与排序 asort依据值排序,键值参与排序 ksort依据键值排序,值参与排序 sort只依据值从小到大排序,键值不参与排序. 例 <?php $arr=a ...

  7. 【CF802C】Heidi and Library (hard) 费用流

    [CF802C]Heidi and Library (hard) 题意:有n个人依次来借书,第i人来的时候要求书店里必须有种类为ai的书,种类为i的书要花费ci块钱购入.而书店的容量只有k,多余的书只 ...

  8. [APP] Android 开发笔记 001-环境搭建与命令行创建项目

    1. 安装JDK,SDK JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html Android SDK http ...

  9. Java秒杀简单设计四:service层设计

    接上一篇 https://www.cnblogs.com/taiguyiba/p/9829191.html  封装了系统传递的数据类和异常类 本文继续设计service层设计: 1.SeckillSe ...

  10. 复杂度O(n)计算

    https://blog.csdn.net/daijin888888/article/details/66970902 一.算法的时间复杂度定义 在进行算法分析时,语句总的执行次数T(n)是关于问题规 ...