poj1426 Find The Multiple
来源:互联网 发布:网络主播能做多久 编辑:程序博客网 时间:2024/06/05 11:34
题意:
给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除。
解题思路:用DFS是搜索 当前位数字 (除最高位固定为1),因为每一位都只有0或1两种选择, 从小往大搜超不出unsigned long long型的范围,每个数都有答案
public class poj1426 { /** * 给出一个整数n,(1 <= n <= 200)。求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成。 从小往大搜超不出unsigned long long型的范围,每个数都有答案 */ static int n,flag; public static void main(String args[]){ Scanner scanner=new Scanner(System.in); while (scanner.hasNext()){ n=scanner.nextInt(); if(n==0){ break; } flag=0; dfs(1,0); } } private static void dfs(long a, int step) { if(flag==1||step>=19){ return ; } if(a%n==0){ flag=1; System.out.println(a); return ; } dfs(a*10,step+1);//搜索只有两个可能0或者1 dfs(a*10+1,step+1); }}
阅读全文
0 0
- 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
- poj1426 find the multiple
- POJ1426 - Find The Multiple
- poj1426 Find The Multiple
- poj1426 Find The Multiple
- poj1426: Find the Multiple
- POJ1426 Find The Multiple
- Robot Framework与Web界面自动化测试学习笔记:简单例子
- 记第一次群面
- 关于自动收集学生作业方法分析
- Servlet与JSP的区别
- 模二运算
- poj1426 Find The Multiple
- Mac下Android Studio调用红米问题
- 观察者模式
- Linux/Android alsa codec音频路由dapm的配置详解
- python3 连接Mysql with pymysal3
- VMware Workstation 12 Pro的安装
- HDU 4630 No Pain No Game
- Tomcat面试题目
- #include预编译的作用