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 ...
随机推荐
- js模块开发
js模块开发(一) 现在嵌入页面里面的javascript代码越来越复杂,于是可能依赖也越来越严重,使用别人开发的js也越来越多,于是在理想情况下,我们只需要实现核心的业务逻辑,其他都可以加载别人已经 ...
- sql优化的50中方法
查询速度慢的原因很多,常见如下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化 ...
- Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
1.错误描写叙述 信息: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10] ...
- Windows在结构objective C开发环境
对于近期打算iPhone.iPod touch和iPad开发一些应用程序,所以.需要开始学习Objective C(苹果推出的类似C语言的开发语言).因为苹果的自我封闭的产业链发展模式(从芯片.机器. ...
- CodeSmith
完美解决CodeSmith无法获取MySQL表及列Description说明注释的方案 问题描述: CodeSmith是现在比较实用的代码生成器,但是我们发现一个问题: 使用CodeSmith编写 ...
- View & ViewData
ViewData 似乎没啥好说的,一个向 View 传送数据的字典. ----------------------------------------------------------------- ...
- html5 图片上传版本1.0
1.代码如下: /* autor:shzihouyu date:2015-12-11 ver:1.0 */ var szyFile = { fileDom:null,//html 文件上传控件 pre ...
- .NET大型B2C开源项目nopcommerce解析——项目结构
.NET大型B2C开源项目nopcommerce解析——项目结构 编写本文档是为了向程序员说明nopcommerce的解决方案结构,亦是程序员开发nopcommerce的居家必备良书.首先nopcom ...
- 个推推送 产品SDK常见问题检查
作者:Hong Jack链接:https://zhuanlan.zhihu.com/p/20733333来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 通知和消息有什么 ...
- Js 数组(一):基础应用
(一) Js 数据类型 分为基本数据类型以及引用类型 基本数据类型有 null,undefined,Boolen,Number,String,还有一种复杂数据类型 Object. var var1 = ...