[kuangbin带你飞]专题一 简单搜索 E
来源:互联网 发布:梯形螺纹加工编程 编辑:程序博客网 时间:2024/06/06 03:16
E - Find The Multiple
POJ - 1426Description
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 soluhem is acceptable.
Sample Input
26190
Sample Output
1010010010010010010011111111111111111
题意:找到一个数是n的倍数,且只能有0,1构成。本来还在想100超过long long 怎么搞。事实上不用想那么多 直接BFS就能过。DFS的话是到20层(long long 范围)。
ACcode:
#include <iostream>#include <cstdio>#include <queue>using namespace std;int n;long long bfs(){ queue<long long> q; q.push(1); while(!q.empty()) { long long p=q.front(); q.pop(); q.push(p*10); if((p*10)%n==0) return (p*10); q.push(p*10+1); if((p*10+1)%n==0) return (p*10+1); } return 0; //一定要加,不加必WA }int main(){ while(scanf("%d",&n)==1 &&n) printf("%lld\n",bfs()); return 0;}
阅读全文
0 0
- [kuangbin带你飞]专题一 简单搜索 E POJ1426
- [kuangbin带你飞]专题一 简单搜索E
- [kuangbin带你飞]专题一 简单搜索 -E
- 1426 [kuangbin带你飞]专题一 简单搜索 E
- [kuangbin带你飞]专题一 简单搜索 E
- [kuangbin带你飞]专题1 简单搜索 E
- [kuangbin带你飞]专题一 简单搜索E - Find The Multiple(POJ 1426)
- [kuangbin带你飞]专题一 简单搜索 E - Find The Multiple poj 1426
- [kuangbin带你飞]专题一 简单搜索 E - Find The Multiple
- [kuangbin神带你飞]专题一 简单搜索
- kuangbin带你飞 专题一 简单搜索 (题解)
- Fire Game [kuangbin带你飞]专题一 简单搜索
- [kuangbin带你飞]专题一 简单搜索 总结
- Kuangbin带你飞专题一 简单搜索
- [kuangbin带你飞]专题一 简单搜索 D - Fliptile
- [kuangbin带你飞]专题一 简单搜索-J - Fire!
- [kuangbin带你飞]专题一 简单搜索 - H - Pots
- [kuangbin带你飞]专题一 简单搜索 A POJ1321
- 依赖倒转原则
- firefox安装不了一些插件,提示版本不兼容
- Bootstrap 显示模态框
- How to fix the problem that the Download rate is too Slow when doing "apt-get install"
- Ubuntu16中vim安装出错–has no installation candidate的解决方法
- [kuangbin带你飞]专题一 简单搜索 E
- 汇编
- 五章通信笔记·概述
- ubuntu下安装Apache+PHP+Mysql
- 【dp】【优化】Problem 791: 硬币
- java小白学习日记
- DJango-如何快速准备Python虚拟开发环境并快速定制一个项目
- 五章通信笔记·电磁场与电磁波
- vim编辑器配置文件