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 ...
随机推荐
- CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)(转载)
在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾斜.移动这四种类型的变形处理,本文将对此做详细介绍. 一.旋转 rotate 用法:transform: rotate(45 ...
- WPF学习记录1:ListView的一个模板
在网上找的一个模板,放在这里,作为笔记,收集 <ListView Grid.Column=" Name="ListmuLu" > <ListView.I ...
- jquery 综合使用例子
效果如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- python学习笔记:python字符串
二.python字符串操作符 1. 对象标准类型操作符 Python对象的标准类型操作符一共就三种:对象值的比较.对象身份的比较.布尔类型.其中对象值的比较主要是大于.小于.不等于等的数学比较符:对象 ...
- Windows 7下 搭建 基于 ssh 的sftp 服务器
Windows xp 下 搭建 基于 ssh 的sftp 服务器,服务器端可以用 freesshd,F-secure server等,filezilla server不可用,之前傻乎乎的用file ...
- Github android客户端源代码分析之一:环境搭建
1.下载相应的包及项目,参考https://github.com/github/android/wiki/Building-From-Eclipse. 2.若需查看某些包的源文件或者javadoc,则 ...
- sublime远程连接到linux主机
sublime远程连接到linux主机 sublime远程连接到linux主机 微信开发,直接使用sublime的sftp功能修改wx_sample.php 1.为sublime安装安装包管理插件Pa ...
- IIS搭建的http文件服务器
使用C#WebClient类访问(上传/下载/删除/列出文件目录)由IIS搭建的http文件服务器 前言 为什么要写这边博文呢?其实,就是使用C#WebClient类访问由IIS搭建的http文件服务 ...
- MEMS开关
MEMS器件在射频比如无线通信上有很好的应用.RF MEMS谐振器和诱导器品质因子在微波上有大幅度提高.MEMS开关极大地改进了高频性能和降低了能耗.本篇概要介绍MEMS开关. 自从1979年彼特森( ...
- IE9 "CSS 因 Mime 类型不匹配而被忽略“问题
写页面的时候在chrome,fireforks等页面上显示正常,但是换成IE9之后就完全没有样式了.IE真是个奇葩的怪胎.它的报错信息是’CSS 因 Mime 类型不匹配而被忽略‘,也就是说所有的.c ...