搜索 H
来源:互联网 发布:纯html源码 编辑:程序博客网 时间:2024/06/06 02:32
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
26190
Sample Output
10100100100100100100111111111111111111
题意:输入一个n 找出 一个十进制的数字,但是由0 1 组成的 ,并且这个数字是n 的倍数
思路:
这个题主要找怎么讲带1和0的数字一一列举出来,从1开始乘10得到一个数,乘10之后再加一。
这个是关键,之后的方法深搜和广搜都是可以的,原来做的用的是深搜,今天重做了,用的广搜,广搜的答案是最小数的答案,其实有的数字答案不唯一,这个题任意一个答案
都可以。
深度搜索方法, 用unsigned long long int 保存 ,深度搜索<20 ,
两条路线 1.t*10;
2.t*10+1;
广搜的方法:
#if 1#include<iostream>#include<queue>using namespace std;void bfs(int n){queue<unsigned long long int> q;q.push(1);while(!q.empty()){unsigned long long int x=q.front();q.pop();if(x%n==0){cout<<x<<endl;return;}q.push(x*10);q.push(x*10+1);}}int main(){int n;while(cin>>n && n){bfs(n);}}#endif
深搜的方法
Code:
#if 0 #include<iostream>#include<cstdio>typedef unsigned long long int longl ; bool pd ; using namespace std;void fun(longl x , int n , int k){ if(pd) return ; if(x%n==0) { pd=true ; printf("%I64u\n", x); return ; } if(k==19) return ; //回溯 fun(x*10,n,k+1) ; //路线1 fun(x*10+1,n,k+1) ; //路线2}int main(){ int n ; while(cin>> n && n!=0 ) { pd=false ; fun (1,n,0); } } #endif
阅读全文
0 0
- 搜索--H
- 搜索 H
- 搜索 H
- 搜索-H
- 搜索-H
- 搜索-H
- 搜索-H
- 搜索专题 H
- 搜索 H题
- 搜索练习题H-08
- eclipse中CTRL+H 搜索
- kuangbin 简单搜索 H题
- 全搜索的H.264编码
- 基础搜索算法题解(D-H)
- eclipse搜索使用_Ctrl+F/H
- Eclipse ,ctrl+h,搜索,拼接正则表达式
- eclipse CTRL+H默认打开文件搜索
- 【搜索入门专题1】hdu2717 H
- jxl返回正确的行列数
- Qt中利用TCP实现客户端与服务器端的数据传输
- 分布式系统常见的事务处理机制
- Android7.0 蓝牙开发官网详解
- 运营界大牛的10年经验干货,拨开运营的谜团
- 搜索 H
- 14.发送邮件
- 通过ip查找域名的网站
- hi3531A tslib,qt4.6.2移植笔记
- 详解 awk 工具的使用方法
- POJ 1239 Increasing Sequences 笔记
- WPF设置控件获得焦点FocusManager
- 读《谈谈方法》
- ActiveMQ的几种集群配置