poj-1426-bfs取余
来源:互联网 发布:java常见类 编辑:程序博客网 时间:2024/05/16 17:45
题意:
给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除。
做法:
假如n=6;
1余n=1;
10余n=1*10%6=4;
11余n=(1*10+1)%6=5;
100余n=4*10%6=4;
101余n=(4*10+1)%6=5;
110余n=5*10%6=2;
111余n=(5*10+1)%6=3;
可以推知10。。。。01余n=(10。。。。0余n*10+1)余n;
#include<iostream>#include<stdio.h>#include<queue>using namespace std;void bfs(int n){ queue<long long>q; q.push(1); while(!q.empty()) { int i; long long x; x=q.front(); q.pop(); if(x%n==0) { printf("%lld\n",x); return ; } q.push(x*10); q.push(x*10+1); }}int main(){ int n; while(scanf("%d",&n)&&n) { bfs(n); } return 0;}
- poj-1426-bfs取余
- poj 1426 bfs+同余模定理
- poj 1426(同余模&&bfs)
- POJ 1426 (BFS + 同余定理)
- poj 1426 bfs+同余定理
- poj 1426 Find The Multiple (bfs+同余定理)
- poj 1426 Find The Multiple ( BFS+同余模定理)
- POJ 1426 Find The Multiple(BFS 同余模定理)
- poj 1426 Find The Multiple bfs+同余模定理
- poj 1426 Find The Multiple(bfs+同余定理)
- POJ 1426 Find The Multiple (BFS + 同余定理)
- POJ 1426 Find The Multiple(BFS+同余模定理)
- POJ 1465 Multiple(BFS+同余剪枝)
- POJ 1465 Multiple (BFS,同余定理)
- POJ--1465--Multiple【BFS+同余定理】
- POJ 3539 同余类BFS
- POJ-1465-bfs,同余剪枝
- poj 2305 Basic remains 高精度取余
- Ubuntu中快捷键的查看及设置
- 多核编程的四层境界
- SQL Server 2008 R2 安装
- 在.NET中利用Google JS V8 Engine实现脚本引擎
- NoSQL新贵MongoDB
- poj-1426-bfs取余
- Struts2中的设计模式----ThreadLocal模式续
- NoSQL数据库的详细分类
- 单源最短路问题
- C# 接口
- 新一轮IDCIICP牌照重新开始 国家调整数据中心建设的合理布局
- android surfaceflinger研究----显示系统
- Stack around the variable was corrupted 解决方案 ---增大栈空间
- 腾讯校招题:fork进程与缓存