ZOJ 1530 - Find The Multiple
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 (0) 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,找n的十进制倍数,仅有 0 和 1 组成,找一个就行,随便哪一个。
解题思路:
观察以下0,1串:
1
10 11
100 101 110 111
从n=1开始, 重复 n*10 与 n*10+1 ,由此遍历所有01串。
BFS,DFS皆可,以下采用DFS。
#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
queue<unsigned long long> s;
int n;//输入
unsigned long long temp,p;
void bfs()
{
while(!s.empty())
s.pop();
temp=;
s.push(temp);
while(!s.empty())
{
p=s.front();
s.pop();
if(p%n==)
{
printf("%lld\n",p);//lld!
break;
}
s.push(p*);
s.push(p*+);
}
}
int main(){
while(scanf("%d",&n),n)
{
bfs();
}
return ;
}
ZOJ 1530 - Find The Multiple的更多相关文章
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- ZOJ 1136 Multiple (BFS)
Multiple Time Limit: 10 Seconds Memory Limit: 32768 KB a program that, given a natural number N ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ 3494 BCD Code(AC自动机+数位DP)
BCD Code Time Limit: 5 Seconds Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...
- zoj 3469 Food Delivery 区间dp + 提前计算费用
Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...
- zoj 3795 Grouping tarjan缩点 + DGA上的最长路
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
- ZOJ 3430 Detect the Virus
传送门: Detect the Virus ...
随机推荐
- jquery中this与$this的区别
来源:http://www.jb51.net/article/19738.htm jQuery中this与$(this)的区别 $("#textbox").hover( funct ...
- django学习笔记二:一个项目多个App项目搭建
django充许在一个项目中存在多个app,如一个大门户网站中可以包含论坛,新闻等内容,其中每一个模块称之为一个App,也可以理解为一个个独立的小型项目最终集成在一个门户网站中最终呈现给用户 本次测试 ...
- html的target用法
_blank -- 在新窗口中打开链接 _parent -- 在父窗体中打开链接 _self -- 在当前窗体打开链接,此为默认值 _top -- 在当前窗体打开链接,并替换当前的整个窗体(框架页), ...
- flex与js相互调用
1.flex调用js方法 调用方法例如:ExternalInterface.call("UploadComplete",oldName,uidName,_dir+"/&q ...
- SonarQube 项目配置文件
费话不说,直接上代码: 需要注意的地方: 1. 每个项目的key不能重复. 2. 注意编码方式. 3. 注意分模块的写法. 4. 忽略源码文件的写法. # Required metadatasonar ...
- list集合接口
import java.util.ArrayList; import java.util.List; class Phone { private String brand; private doubl ...
- bluestacks安装安卓引擎时出现2502 2503错误的解决办法
2503代表工作站无法启动.2502代表下面的程序调用不支持的MS-DOS函数. 以管理员身份运行命令提示符在经典桌面使用快捷键Win+X,出现一个菜单,选择“命令提示符(管理员) ”即可以以管理员身 ...
- Android的动画
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...
- win8上安装 Pillow
1.确保正确安装pip(2.7.9默认安装) 2. pip install wheel 3.下载 pillow-*.whl 根据自己的电脑和python版本 地址 4.安装 pip install x ...
- VB.NET生成Excel,已存在提示框点否时报错
如题 Exception from HRESULT: 0x800A03EC 最终没有好的解决方案,只好屏蔽掉 Try obook.SaveAs(excelSaveName) Catch ex As S ...