hdu4474 Yet Another Multiple Problem
Description
In this problem, you’re asked to solve the following question: Given a positive integer n and m decimal digits, what is the minimal positive multiple of n whose decimal notation does not contain any of the given digits?
Input
For each test case, there are two lines. The first line contains two integers n and m (1 ≤ n ≤ 10
4). The second line contains m decimal digits separated by spaces.
Input is terminated by EOF.
Output
Sample Input
7 8 9
100 1
0
Sample Output
Case 2: -1
#include <iostream>
#include <queue>
#include <string>
#include <string.h>
#include <stdio.h>
using namespace std;
struct node{
int x;
string re;
};
queue<node> q;
int numcan[12],visit[10050],n;
char str[2];
int bfs()
{
node temp,ptop;
int i,modi;
str[1]='\0';
memset(visit,0,sizeof(visit));
while(!q.empty())
{
q.pop();
} for(i=1;i<=9;i++)//第一位不为0
{
if(numcan[i])
{
modi=i%n; temp.x=modi;
str[0]=i+'0'; temp.re=str; visit[modi]=1;
if(modi==0)
{
cout<<temp.re<<endl;
return 1;
}
q.push(temp);
}
}
while(!q.empty())
{
ptop=q.front();
q.pop();
for(i=0;i<=9;i++)
{ if(numcan[i])
{
modi=(ptop.x*10+i)%n;
if(modi==0)
{
cout<<ptop.re<<i<<endl;
return 1;
}
if(!visit[modi])
{
visit[modi]=1;
str[0]=i+'0';
temp.re=ptop.re+str;
temp.x=modi;
q.push(temp); }
}
} }
printf("-1\n");
return -1;
}
int main()
{
int m,tcase,i,num;
tcase=1;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<10;i++)
{
numcan[i]=1;
}
for(i=0;i<m;i++)
{
scanf("%d",&num);
numcan[num]=0;
}
printf("Case %d: ",tcase++);
bfs();
}
return 0;
}
hdu4474 Yet Another Multiple Problem的更多相关文章
- 2012Chhengdu K - Yet Another Multiple Problem
K - Yet Another Multiple Problem Time Limit:20000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- Yet Another Multiple Problem(bfs好题)
Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other) Memory Limit : 65536/65536K ( ...
- HDU-4471 Yet Another Multiple Problem (BFS+路径还原)
Problem Description There are tons of problems about integer multiples. Despite the fact that the to ...
- HDU 4474 Yet Another Multiple Problem【2012成都regional K题】 【BFS+一个判断技巧】
Yet Another Multiple Problem Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 65536/65536 K ...
- hdu 4474 Yet Another Multiple Problem
题意: 找到一个n的倍数,这个数不能含有m个后续数字中的任何一个 题解: #include<stdio.h> #include<string.h> #include<qu ...
- HDU4474_Yet Another Multiple Problem
题意很简单,要你用一些数字,组成一个数的倍数,且那个数最小. 比赛的时候没能做出来,深坑啊. 其实我只想说我以前就做过这种类型的题目了,诶. 题目的解法是数位宽搜. 首先把可用的数位提取出来,从小到大 ...
- HDU 4474 Yet Another Multiple Problem ( BFS + 同余剪枝 )
没什么巧办法,直接搜就行. 用余数作为每个节点的哈希值. #include <cstdio> #include <cstring> #include <cstdlib&g ...
- HDU 4474 Yet Another Multiple Problem BFS
题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0 1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...
- K - Least Common Multiple
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
随机推荐
- 如何将经纬度利用Google Map API显示C# VS2005 Sample Code
原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上 ...
- MEF框架在Silverlight中应用(15)
原文:MEF框架在Silverlight中应用(15) MEF框架在Silverlight中应用 代码下载 MEF框架是微软提供的一个插件框架.应用概括为一句话:输入,输出,组合.下面是具体在Silv ...
- Android基础之——startActivityForResult启动界面并返回数据,上传头像
在android应用的开发过程中,常常会出现启动一个界面后填写部分内容后带着数据返回启动前的界面,最典型的应用就是登录过程.在非常多应用程序的模块中,都有"我的"这个模块,在未登录 ...
- Require.JS 2.0
就在前天晚上RequireJS发布了一个大版本,直接从version1.0.8升级到了2.0.随后的几小时James Burke又迅速的将版本调整为2.0.1,当然其配套的打包压缩工具r.js也同时升 ...
- NYOJ 14 场地安排(它可以被视为一个经典问题)
会场安排问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 学校的小礼堂每天都会有很多活动.有时间这些活动的计划时间会发生冲突,须要选择出一些活动进行举办.小刘的工 ...
- Scala Sublime text 3 Build 编译
使用Sublime text 3编译Scala 在sublime工具栏中[tools]->[Build System]->[new Build System]添加如下文本 { " ...
- 使用Oracle 9i工具管理数据库 - 初学者系列 - 学习者系列文章
前面介绍了Oracle 9i的安装,本文大概介绍下Oracle 9i提供的管理工具的使用. 1 打开数据库配置工具 2 下一步 3 下一步 4 下一步.这里输入数据库名和SID 5 下一步 6 下一步 ...
- Entity Framework 丢失数据链接的绑定,在已绑好的EDMX中提示“Choose Your Data Connection”
早先做的一个练手的项目中, 使用到了Entity framework . 最近碰到一个问题,在edmx 里面选择“Update model from Database” 的时候提示了 “Choose ...
- 开源框架之TAB控件
我的开源框架之TAB控件 需求 (1)支持iframe.html.json格式的tab内容远程请求 (2)支持动态添加tab (3)支持远程加载完成监听,支持tab激活事件监听 (4)支持relo ...
- MVC 插件式开发
MVC 插件式开发 在开发一个OA系统是,我们可能遇到 A模块. B模块 .C模块,这也模块组成一个完整的系统,买给客服.现在又有一个客服要我们做一个OA系统,唉我们发现,跟上一个OA系统差不多,但没 ...