题意:

  找到一个n的倍数,这个数不能含有m个后续数字中的任何一个

题解:

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
queue<int>que;
int used[];
int flag[],pre[],value[];
int n,m;
void print(int n)
{
if(n!=-)
{
print(pre[n]);
printf("%d",value[n]);
}
}
void bfs()
{
for(int i=; i<=; i++)
{
if(!used[i]&&!flag[i%n])
{
que.push(i%n);
flag[i%n]=;
pre[i%n]=-;
value[i%n]=i;
}
}
while(!que.empty())
{
int temp=que.front();
if(temp==)
{
print(pre[temp]);
printf("%d\n",value[temp]);
return ;
}
else
for(int i=; i<=; i++)
{
if(!used[i]&&!flag[(temp*+i)%n])
{
que.push((temp*+i)%n);
flag[(temp*+i)%n]=;
pre[(temp*+i)%n]=temp;
value[(temp*+i)%n]=i;
}
}
que.pop();
}
printf("-1\n");
return ;
}
int main()
{
int ncase=,m1;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(used,,sizeof(used));
memset(flag,,sizeof(flag));
while(!que.empty())
que.pop();
for(int i=; i<m; i++)
{
scanf("%d",&m1);
if(!used[m1])
used[m1]=;
}
printf("Case %d: ",ncase++);
bfs();
}
return ;
}

广搜,同余剪枝

 A=MX+R
B=NX+R
假设A,B对于X的余数相同
那么
(10*A+d[i])%x
(10*B+d[i])%x
的意义是一样的,所以只有当余数没出现过的情况下才加入到搜索的队列中来

hdu 4474 Yet Another Multiple Problem的更多相关文章

  1. 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 ...

  2. HDU 4474 Yet Another Multiple Problem ( BFS + 同余剪枝 )

    没什么巧办法,直接搜就行. 用余数作为每个节点的哈希值. #include <cstdio> #include <cstring> #include <cstdlib&g ...

  3. HDU 4474 Yet Another Multiple Problem BFS

    题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0  1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...

  4. 2012Chhengdu K - Yet Another Multiple Problem

    K - Yet Another Multiple Problem Time Limit:20000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】

    Least Common Multiple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  6. ACM hdu 1019 Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  7. Yet Another Multiple Problem(bfs好题)

    Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other)   Memory Limit : 65536/65536K ( ...

  8. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

  9. hdu4474 Yet Another Multiple Problem

    Yet Another Multiple Problem Description There are tons of problems about integer multiples. Despite ...

随机推荐

  1. webstorm 添加文件模板

    Ctrl+Shift+A 搜索设置 File Teamplate ​ 添加 File Teamplate

  2. ArcGIS API for JavaScript介绍

    ArcGIS API for JavaScript中的类是按照模块组织的,主要包含esri.esri/geometry.esri/renderers.esri/symbols.esri/symbols ...

  3. JS中的this用法详解

    随着对js的深入学习和使用,你会发现它里面包含了很多令人困惑的机制,比如对象.闭包.原型链继承等等,而这其中肯定包含令你现在或者曾经费解的this,如果你不把心一横,花点时间还真不明白这个this的用 ...

  4. TDirectory.CreateDirectory 完整、严谨的创建一个目录

    描述:创建一个目录,不包含多级目录(多级目录使用System.SysUtils.ForceDirectories,Vcl.FileCtrl.ForceDirectories已过时) procedure ...

  5. 你必须知道的.NET

    作者博客地址:http://www.cnblogs.com/anytao/archive/2008/04/09/anytao_insidenet_center.html 第1章 OO大智慧 1.1对象 ...

  6. 1049. Counting Ones/整数中1出现的次数(从1到n整数中1出现的次数)

    The task is simple: given any positive integer N, you are supposed to count the total number of 1's ...

  7. MySQL 死锁日志分析

    ------------------------ LATEST DETECTED DEADLOCK ------------------------ 140824  1:01:24 *** (1) T ...

  8. 7、XAML的编译过程

    对于动态皮肤场景来说,在运行时加载和解析XAML是有意义的,对于那些没有支持XAML编译的.NET语言也是有意义的.但大多数WPF项目会通过MSBuild和Visual Studio完成XAML编译. ...

  9. 0x04 高级语法

    while-endw .while(条件) 循环体(条件满足时执行) .endw repeat-until .repeat 循环体(条件不满足时执行) .until(条件) if-elseif-end ...

  10. Wireshark 入门

    1.过滤目的地是百度的IP包. 百度的ip: 命令:ip.src eq 61.135.169.125 过滤ip来源是61.135.169.125 ip.dst eq 61.135.169.125 过滤 ...