POJ1426 Find The Multiple DFS
来源:互联网 发布:sql编程基础 编辑:程序博客网 时间:2024/06/17 05:36
题解:
题目给你一个n,然后让你用0和1组成的十进制数如果能满足这个数%n==0就可以输出,因为n最多有到200,所以一开始并不知道是不是要大数了…后来发现用unsigned long long 就可以,具体的看代码吧
代码
#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>using namespace std;#define MAX 100000#define LL long longint cas=1,T;int flag = 0;void dfs(unsigned long long t,int n,int step){ if (flag) return; if (t%n==0) { printf("%llu\n",t); flag=1; return; } if (step==19) //再搜索下去就要溢出了 return; dfs(t*10,n,step+1); dfs(t*10+1,n,step+1);}int main(){ int n; while (scanf("%d",&n) && n) { flag=0; dfs(1,n,0); } //freopen("in","r",stdin); //scanf("%d",&T); //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); return 0;}
题目
Find The Multiple
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
POJ 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
- POJ1426 Find The Multiple DFS
- POJ1426 Find The Multiple(DFS)
- Find The Multiple poj1426 (DFS)
- POJ1426 Find The Multiple (BFS | DFS)
- POJ1426 Find The Multiple(深搜DFS)
- poj1426 Find The Multiple dfs搜索答案
- POJ1426 Find The Multiple
- poj1426 Find The Multiple
- poj1426 - Find The Multiple
- POJ1426 Find The Multiple
- POJ1426-Find The Multiple
- poj1426 Find The Multiple
- poj1426-Find The Multiple
- POJ1426 Find the multiple
- POJ1426-Find The Multiple
- POJ1426 Find The Multiple
- poj1426 Find The Multiple
- Find The Multiple poj1426
- 几款强力压缩打包软件
- 理解MyGUI3.2.0及其Samples的运行实质
- android studio 更换包名
- 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。
- 随笔
- POJ1426 Find The Multiple DFS
- leetcode:160 Intersection of Two Linked Lists-每日编程第二十九题
- jQuery中.live()方法的用法深入解析
- project euler 85
- iOS9新特性
- project euler 86
- Ubuntu 创建 eclipse launcher
- 解决Android使用第三方库.so自动删除问题
- 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。