poj 1426 Find The Multiple
来源:互联网 发布:手机淘宝如何上架宝贝 编辑:程序博客网 时间:2024/06/03 14:47
题目链接:点击打开链接
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 找出是n的倍数m 而且m是只有0和1组成的
基本思路:dfs和bfs都可以,我用的bfs;首先用long long 存储是可以放开的,然后就是暴力搜索,从1开始然后对其乘10和乘10+1,直到出现结果.
我看的别人的博客都用同的dfs 一开始写的bfs也是超内存,但是想到用队列可以去除队前的数,从而使得数据会减少从而ac
<span style="font-size:18px;">#include <iostream>#include<cstring>#include<queue>using namespace std;unsigned long long b;queue<unsigned long long>a;int main(){ int n; while(cin>>n,n) { while(!a.empty()) { a.pop(); } a.push(1); while(!a.empty()) { b=a.front(); a.pop(); if(b%n==0) { break; } else { a.push(b*10); a.push(b*10+1); } } cout<<b<<endl; } return 0;}</span>
0 0
- poj 1426 Find The Multiple
- Poj 1426 Find The Multiple
- POJ 1426 Find the Multiple
- poj 1426Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj - 1426 - Find The Multiple
- POJ 1426 Find The Multiple
- POJ-1426-Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj 1426 Find The Multiple
- POJ 1426 Find The Multiple
- 大数据Spark “蘑菇云”行动前传第9课:Scala类和对象彻底实战和Spark源码鉴赏
- Service生命周期
- 多核和单核中多线程及单线程的特点
- emmc/sd 核心层解析
- Android View 下拉上拉刷新 适合各种控件
- poj 1426 Find The Multiple
- hashmap两种遍历总结!
- Java正则表达式
- ramfs,rootfs,initramfs,initrd
- 中软Java学习笔记第二天
- 2016多校联合3
- [HihoCoder]#1289 : 403 Forbidden
- spark配置IntelliJ开发环境详解
- Mini2440烧写Linux系统