51nod 1109 01组成的N的倍数 【dfs+剪枝+vector】
来源:互联网 发布:java方法引用 编辑:程序博客网 时间:2024/06/06 03:22
1109 01组成的N的倍数
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
给定一个自然数N,找出一个M,使得M > 0且M是N的倍数,并且M的10进制表示只包含0或1。求最小的M。
例如:N = 4,M = 100。
Input
输入1个数N。(1 <= N <= 10^6)
Output
输出符合条件的最小的M。
Input示例
4
Output示例
100
代码:
#include<cstdio>#include<vector>#include<queue>#include<cstring>#include<algorithm>using namespace std;bool yu[1000100];struct node{ vector<char> ch; int shu;}now,qian;int main(){ int n; scanf("%d",&n); if(n==1) printf("1\n"); else { queue<node> que; now.shu=1; now.ch.push_back('1'); que.push(now); int a,b;yu[1]=true; bool fafe=false; while (true) { now=que.front(); que.pop(); a=now.shu*10; for (int i=0;i<2;i++) { b=(a+i)%n; if (b==0) { for (int i=0;i<now.ch.size();i++) printf("%c",now.ch[i]); printf("%d\n",i); fafe=true; break; } if (yu[b]) continue; yu[b]=true; qian.ch=now.ch; qian.ch.push_back(i+48); qian.shu=b; que.push(qian); } if (fafe) break; } } return 0;}
0 0
- 51nod 1109 01组成的N的倍数 【dfs+剪枝+vector】
- 51nod 1109 01组成的N的倍数【Bfs+同余定理剪枝】好题!
- 51nod 1109 01组成的N的倍数(宽搜+剪枝)
- 51nod-1109 01组成的N的倍数(宽搜)
- 【51Nod 1109】01组成的N的倍数
- 51nod 1109 01组成的N的倍数+
- 51NOD 1109 01组成的N的倍数
- 51nod 1109 01组成的N的倍数
- 51nod 1109 01组成的N的倍数(bfs)
- 51nod 1109 01组成的N的倍数
- 51 nod 1109 01组成的N的倍数
- 51nod 1109 01组成的N的倍数
- 51Nod 1109 01组成的N的倍数
- 51Nod-1109-01组成的N的倍数
- 51nod 01组成的N的倍数(bfs)
- 51nod 1109 01 组成N倍数 bfs+同余剪枝
- 51Nod-1109-01组成的N的倍数
- 51nod 1109 01组成的N的倍数 (bfs)
- 一篇文章带你搞懂DEX文件的结构
- Git中经常使用的命令小结
- Gym 100796C Minimax Tree
- 413 Request Entity Too Large 的解决方法
- ubuntu 12.04安装telnet和ssh服务
- 51nod 1109 01组成的N的倍数 【dfs+剪枝+vector】
- 实现Java读取网页内容并下载网页中出现的图片
- IDEA 安装过程插件选择
- 关于装msdn网站纯净版win7正版授权问题(已解决)
- ACM竞赛需要注意的一些编程习惯
- 2017.02.18 这一周的面试
- centos7 用root用户重新设置普通用户密码
- FindBugs规则整理
- POJ 3427 Ecology tax G++