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. .net写入文本到本地

    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"d:\test\ErrorLog.txt", t ...

  2. 《转》Python学习(17)-python函数基础部分

    http://www.cnblogs.com/BeginMan/p/3171977.html 一.什么是函数.方法.过程 推荐阅读:http://www.cnblogs.com/snandy/arch ...

  3. Java 8 特性 – 终极手册

    简介 毫无疑问,Java 8的发布是自Java 5(它的发布已远在2004年)以来在Java世界中最重大的事情.它带来了超多的新特性,这些特性分别被加入到Java语言本身.Java编译器.类库.工具类 ...

  4. 六、K3 WISE 开发插件《直接SQL报表开发新手指导 - BOM成本报表》

    ======================== 目录: 1.直接SQL报表 ======================== 1.直接SQL报表 以BOM成本报表为例,在销售模块部署,需要购买[金蝶 ...

  5. 关于egret.Tween传递参数的问题

    参考: setTimeOut传参数(转) setTimeout传参数 CSDN 一.延迟后执行,并输出参数 for(let i=0;i<10;i++){ egret.Tween.get(this ...

  6. Linux下常用命令wget的使用技巧

    Linux下wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,尤其对于网络管理员 经常要下载一些软件或从远程服务器恢复备份到本地服务器.如果我们使用虚拟主机,处理这样的 ...

  7. windows_xp下卸载office2003报无法打开此修补程序包错误

    今天在给公司一同事装完xp系统后.准备卸载预安装的Microsoft office2003,然后安装Microsoft office2007.结果在卸载office2003时报如下错误. 经过上网查询 ...

  8. python-django开发学习笔记四

    先插入一条广告,博主新开了一家淘宝店,经营自己纯手工做的发饰,新店开业,只为信誉!需要的亲们可以光顾一下!谢谢大家的支持!店名: 小鱼尼莫手工饰品店经营: 发饰.头花.发夹.耳环等(手工制作)网店: ...

  9. mysql max(),min()的优化

    Select tables optimized away(选择表优化)

  10. octomap的简介

    装载自高翔博士的博客:https://www.cnblogs.com/gaoxiang12/p/5041142.html 什么是octomap? RGBD SLAM的目的有两个:估计机器人的轨迹,并建 ...