POJ 1426 Find The Multiple【dfs】
来源:互联网 发布:vb 播放器 编辑:程序博客网 时间:2024/05/21 17:06
Find The Multiple
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 22877
Accepted: 9431
Special Judge
Description
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;}
- 【DFS】poj 1426 Find The Multiple
- POJ 1426 Find The Multiple(DFS构造)
- POJ 1426 Find The Multiple (DFS)
- POJ 1426 Find The Multiple (DFS + 构造)
- Poj 1426 Find The Multiple 【DFS】
- POJ - 1426 - Find The Multiple (DFS)
- POJ 1426 Find The Multiple(dfs)
- DFS-POJ-1426-Find The Multiple
- poj 1426 Find The Multiple ( dfs )
- POJ 1426 Find The Multiple(dfs)
- POJ 1426 Find The Multiple(dfs)
- POJ 1426 Find The Multiple (dfs)
- POJ 1426 Find The Multiple【dfs】
- POJ 1426 Find The Multiple(dfs)
- poj 1426 Find The Multiple dfs
- POJ 1426 Find The Multiple dfs
- poj 1426 Find The Multiple (bfs / dfs)
- poj 1426 Find The Multiple(DFS)
- ssh远程连接Ubuntu
- 我的iOS学习历程 - UITableView的编辑
- WebGL实现HTML5贪吃蛇3D游戏
- Linux 非缓冲I/O与缓冲I/O
- { Cracking The Coding Interview: 150 programming Q&A } 5th edition Part I
- POJ 1426 Find The Multiple【dfs】
- C语言的那些小秘密之异常处理
- CSP应用开发-CryptAPI解析X509及PKCS#12证书
- HDU 4548 美素数【素数打表】
- 堆和栈的区别
- 第一次调研甲方的工作总结
- 不用加减乘除做运算
- mybatis 一级缓存和二级缓存简介
- 版瓦工VPS搭建VPN