POJ ——1465(宽度搜索)
来源:互联网 发布:layabox js教程 编辑:程序博客网 时间:2024/06/05 02:34
题目链接:http://poj.org/problem?id=1465
源代码:
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int m,n;
int flag[5050];
int a[5000];
struct Que
{
int digite;
int mod;
int pre;
}queue[5000];
void output(Que t)
{
if(t.pre!=-1)
{
output(queue[t.pre]);
cout<<t.digite;
}
}
void bfs()
{
int front,per;
int sign=0;
queue[0].digite=0;
queue[0].mod=0;
queue[0].pre=-1;
front=0;
per=1;
int r;
while(front<per)
{
Que t;
Que moder=queue[front];
for(int i=0;i<n;i++)
{
r=(moder.mod*10+a[i])%m;
if(!flag[r]&&(moder.pre!=-1||a[i]>0))
{
flag[r]=1;
t.digite=a[i];
t.mod=r;
t.pre=front;
queue[per++]=t;
if(r==0)
{
output(t);
cout<<endl;
sign=1;
break;
}
}
}
front++;
if(sign) break;
}
if(!sign) cout<<"0"<<endl;
}
int main()
{
while(cin>>m)
{
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
memset(flag,0,sizeof(flag));
sort(a,a+n);
if(m==0)
{
cout<<"0"<<endl;
continue;
}
bfs();
}
return 0;
}
- POJ ——1465(宽度搜索)
- poj 3278(bfs宽度优先搜索)
- ZOJ——1649(宽度搜索)
- Prime Path - POJ 3126 BFS宽度(广度)优先搜索
- BFS-宽度优先搜索(Breadth First Search)—1
- BFS 宽度优先搜索——初学
- coj1224(宽度优先搜索)
- 宽度优先搜索(BFS)
- BFS(宽度优先搜索)
- 宽度优先搜索(BFS)
- POJ-3669的基础上输出逃生路径(bfs)(宽度优先搜索)
- POJ——2488(深度搜索)
- 宽度优先搜索(BFS)的应用——走迷宫
- 宽度优先搜索——迷宫的最短路径
- 宽度搜索
- POJ 3626 Mud Puddles 练习 BFS 宽度优先搜索
- poj 3984 迷宫问题 宽度搜索 一个终点
- POJ 1979 —— 搜索
- 降低印花税以后股市会如何?(http://blog.sina.com.cn/s/blog_4cc2179501015lgj.html)
- 在服务器(IIS)搭建测试环境
- flash元件做运行时共享的问题
- dll远程注入部分代码
- Oracle获取毫秒和年月日到毫秒方法
- POJ ——1465(宽度搜索)
- 4.SimpleTrigger:声明式调度器
- 在外存存储图片的一个典型示例
- 为什么使用%lf读取double型的值,而用%f进行显示?
- 5.SimpleTrigger:quartz_jobs.xml
- 自己动手实现Maven Plugin
- 遥控器测试程序相关技术文档
- Oracle数据库中把一个查询结果插入到一张表中
- Javascript世界中的一等公民——函数