POJ 1426 Find The Multiple【dfs】
2015-11-25 11:34
267 查看
Find The Multiple
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22877 | Accepted: 9431 | Special Judge |
Given a positiveinteger n, write a program to find out a nonzero multiple m of n whose decimalrepresentation contains only the digits 0 and 1. You may assume that n is notgreater than 200 and there is a corresponding m containing no more than
100decimal digits.
Input
The input file maycontain 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 ofn in the input print a line containing the corresponding value of m. Thedecimal representation of m must not contain more than 100 digits. If there aremultiple 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),求任意一个N的倍数M*N【这个是我设】,使得数的十进制位每位都是由0或1组成。任意输出一组解就行。题目保证有解。思路:
__int64可以装下。那么最多到达20个十进制位,那么就可以直接dfs水过了=_=实现代码:
#include <queue> #include <cmath> #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) typedef long long LL; int N; bool suc; void dfs(LL M, int bit) { if(bit >= 20 || suc) return; if(M % N == 0) { suc = true; printf("%I64d\n", M); return; } dfs(M * 10, bit + 1); dfs(M * 10 + 1, bit + 1); } int main() { // FIN; while(~scanf("%d", &N) && N) { suc = false; dfs(1, 1); } return 0; }
相关文章推荐
- Git的深入理解与GitHub托管服务的使用
- 裁减jar包
- Genero DB Connect
- ORACLE 创建自增序列生成流水号
- Android工程项目解析
- 关于Android程序入口的猜想
- Spring中JdbcTemplate使用RowMapper(简单明了的代码)
- UIButton 点击后变灰
- 服务器上传文件大小限制
- sublime Text3之保存刷新 Browser Refresh
- Android studio 上获取应用签名文件(keystore文件)的MD5值
- 颜如玉——11月第四周
- 基于标记的AR的opencv实现(一)
- WPF ScrollViewer 样式
- Spring使用JdbcTemplate实现对数据库操作 (内部类定义RowMapper)
- ios 常用基础框架
- web 中的数据分页显示
- eclipse项目迁移到android studio(图文最新版)
- nginx编译安装与常规配置
- Qt之界面实现技巧