POJ 1426 见证模余的力量!
来源:互联网 发布:淘宝图片保护在哪里看 编辑:程序博客网 时间:2024/05/29 15:56
核心思想:
同余的数只保留一个就足够了。
/*
source: POJ t1426
algorithm: BFS
author: wangmeng @ flame
date: 2009-8-16
*/
#include<iostream>
#include <queue>
using namespace std;
int main()
{
int n;
int front;
int next1;
int next2;
bool inQueue[200];
long long sequence[200] = {0};
queue<int> q;
while ((cin >> n) && (n != 0))
{
// initialize data
memset(sequence, 0, sizeof(sequence));
memset(inQueue, false, sizeof(inQueue));
sequence[1] = 1;
inQueue[1] = true;
while (!q.empty())
q.pop();
q.push(1);
// creat graph
while (!inQueue[0])
{
front = q.front();
q.pop();
next1 = (front * 10) % n;
next2 = (next1 + 1) % n;
if (!inQueue[next1])
{
q.push(next1);
inQueue[next1] = true;
sequence[next1] = sequence[front] * 10;
}
if (!inQueue[next2])
{
q.push(next2);
inQueue[next2] = true;
sequence[next2] = sequence[front] *10 + 1;
}
}
cout << sequence[0]<<endl;
}
return 0;
}
- POJ 1426 见证模余的力量!
- Android系统:见证“开源”的力量
- poj 1426 bfs+同余模定理
- poj 1426(同余模&&bfs)
- PAY WATCH淘宝众筹首发——见证创想的力量
- 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 && 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)
- POJ 2769 简单的同余问题
- POJ 1426 (BFS + 同余定理)
- poj 1426 bfs+同余定理
- 见证的影像志
- 爱的见证
- 2008------岁月的见证
- poj 2635 同余模定理
- squid-2.6.STABLE13 修改手记
- [转载] C语言中如何使用宏 包括单双井号 可变参数
- 转载-----C# 设计模式 - 1 接口模式 - 1.1 适配器模式
- 泛型算法系列20:reverse()&&reverse_copy()
- 【转】单例模式完全剖析
- POJ 1426 见证模余的力量!
- JDK1.5新特性(转)
- oracle 10g rac for linux (ASM) 修改modify public IP and vip
- emacs初学,大家有意见就提哈
- 接口模式 - 1.1 适配器模式 --代码实现(C#)
- 程序员的十层楼
- hibernate的lazy使用
- ISAPI过滤器介绍与使用
- ZOJ 1276 纪录路径的DP,生成括号的方法很有效