题意:

  找到一个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. 【Qt】Qt Creator介绍【转】

    简介 Qt Creator是使用Qt开发的IDE.Qt支持Windows.Linux/Unix.Mac OS X.Android.BlackBerry.QNX等多种平台,Qt Creator为不同平台 ...

  2. 分享:PHP数组排序总结

    本文内容:PHP二维数组排序,PHP数组排序总结. php数组排序是PHP学习中最基础也是最重要的一部分. 1.常规数组的排序 常规数组是指数组各元素均为字符串或数字,这与这样的数组,我们可以采用so ...

  3. setEllipsize(TruncateAt where)

    void android.widget.TextView.setEllipsize(TruncateAt where) public void setEllipsize (TextUtils.Trun ...

  4. Ajax入门小例子

    大牛文章:http://www.cnblogs.com/guduoduo/p/3681296.html                               ---Ajax基础学习 http:/ ...

  5. R简易入门(一)

    本文内容来源:https://www.dataquest.io/mission/126/introduction-to-r 本文数据来源:https://www.whitehouse.gov/21st ...

  6. 在Java中执行js代码

    在某些特定场景下,我们需要用Java来执行Js代码(如模拟登录时,密码被JS加密了的情况),操作如下: ScriptEngineManager mgr = new ScriptEngineManage ...

  7. hdu 5755 2016 Multi-University Training Contest 3 Gambler Bo 高斯消元模3同余方程

    http://acm.hdu.edu.cn/showproblem.php?pid=5755 题意:一个N*M的矩阵,改变一个格子,本身+2,四周+1.同时mod 3;问操作多少次,矩阵变为全0.输出 ...

  8. Linux使用标准IO的调用函数,分3种形式实现

    /*根据cp命令的格式要求,设计一个类cp的功能程序,要求使用标准IO的调用函数,分3种形式实现,字符,行,块.并注意函数功能的分层*/ #include<stdio.h> #includ ...

  9. linux下gcc编译的参数详细说明

    参考网址:1 http://hi.baidu.com/zengzhaonong/item/f1f9383565fa5c302e0f8125 gcc使用方法 汇总 2 http://s99f.blog. ...

  10. [MVC] - 异步调用后台的常用方法。

    1. 直接调用Action @Html.Action("GetTopArticle", "Home") 2. 通过url, 并用Jquery异步加载. < ...