题意:

  找到一个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. mysql主从复制-linux版本

    来自:http://www.osyunwei.com/archives/7269.html,改版 mysql主从复制本文采用的是centos6.5+mysql-5.6.23版本之前在 windows7 ...

  2. web前端--知识点,笔记叠加(javascript,jquery,html5+css3.0,ajax)

    函数传参列表,获取方法arguments的使用 function arg(){ var str = '总共传了'+arguments.length+'个参数\n'; for(var i=0;i< ...

  3. 了解jsonp

    <script>                //创建全局函数,用来处理 跨域 获取到的信息:        function name(data){            ....   ...

  4. C#中Delegate

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 【Web学习日记】——在IIS上发布一个WebService

    没有开发过程,只是发布过程 一.前提 开发使用的是VS2013 从来没有做过Web的发布,在网上找例子,看到的总是与自己的情况不相符,而且也有人提出了VS2013发布网站的问题,但解决方案却很少,好不 ...

  6. oracle-12c-rac 报:ORA-01078

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - ...

  7. vim命令总结

    前言 本文翻译自:http://bencrowder.net/files/vim-fu/,参考了VIM中文帮助. Google翻译结果和实际操作结果,对原文的部分内容重新整理,删除和添加了 部分内容并 ...

  8. python之域与属性

    python, javascript中域与属性是二个不同的概念, 域就是变量, 而属性则是符合某些约束, 例如getter, setter...等的特殊"变量". python中使 ...

  9. 使用ab测试工具 进行并发测试

    ab.exe -n1000 -c100 http://localhost:8067/api/todo/555e95feb301baa678141148 http://www.cnblogs.com/y ...

  10. topcoder 673

    DiV1 300:给一组士兵再给一组战马都有权值. 安排战马的顺序的方案数,是第一个士兵和其战马的权值乘积最大. 做法:随便暴力就好. 枚举战马和第一个士兵匹配.其他士兵按权值从大到小排序,战马权值按 ...