没什么巧办法,直接搜就行。

用余数作为每个节点的哈希值。

#include <cstdio>
#include <cstring>
#include <cstdlib> const int MAXN = ; struct node
{
int mod;
int fa;
int digit;
node() {}
node( int mod, int fa, int dig ):mod(mod), fa(fa), digit(dig) { }
}; int N;
bool ok[];
bool vis[MAXN];
node Q[MAXN << ]; void findFa( int u )
{
if ( u == - ) return;
findFa( Q[u].fa );
printf( "%d", Q[u].digit );
} int BFS()
{
int head = ;
int tail = ;
memset( vis, false, sizeof(vis) ); for ( int i = ; i < ; ++i )
{
if ( !ok[i] ) continue;
int hashh = i % N;
if ( vis[hashh] ) continue;
vis[hashh] = true;
Q[tail] = node( hashh, -, i );
if ( hashh == ) return tail;
++tail;
} while ( head < tail )
{
node cur = Q[head];
for ( int i = ; i < ; ++i )
{
if ( !ok[i] ) continue;
int hashh = ( cur.mod * + i ) % N; if ( vis[hashh] ) continue;
vis[hashh] = true;
Q[tail] = node( hashh, head, i );
if ( hashh == ) return tail;
++tail;
}
++head;
}
return -;
} int main()
{
int cas = ;
while ( scanf( "%d", &N ) == )
{
memset( ok, true, sizeof(ok) );
int n;
scanf( "%d", &n );
for ( int i = ; i < n; ++i )
{
int digit;
scanf( "%d", &digit );
ok[digit] = false;
} printf( "Case %d: ", ++cas );
int ans = BFS();
if ( ans != - ) findFa( ans );
else printf("-1"); puts("");
}
return ;
}

HDU 4474 Yet Another Multiple Problem ( BFS + 同余剪枝 )的更多相关文章

  1. HDU 4474 Yet Another Multiple Problem BFS

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

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

  3. hdu 4474 Yet Another Multiple Problem

    题意: 找到一个n的倍数,这个数不能含有m个后续数字中的任何一个 题解: #include<stdio.h> #include<string.h> #include<qu ...

  4. Yet Another Multiple Problem(bfs好题)

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

  5. (简单) POJ 1426 Find The Multiple,BFS+同余。

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

  6. hdu 4474 大整数取模+bfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474 (a*10+b)%c = ((a%c)*10+b%c)%c; 然后从高位开始枚举能填的数字填充, ...

  7. hdu 1689 Alien’s Necklace (bfs层次图剪枝)

    Alien's Necklace Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. SPOJ 370 Ones and zeros BFS + 同余剪枝

    题意:给一些n,求出最小的只包含0,1的n的倍数 设两数a, b满足: a < b 并且a % n = b % n. 如果 ( a * 10^x + c ) % n = z , 根据同余定理,( ...

  9. HDU-4471 Yet Another Multiple Problem (BFS+路径还原)

    Problem Description There are tons of problems about integer multiples. Despite the fact that the to ...

随机推荐

  1. 分布式系统session一致性问题

    一.引言 1.什么是session Session 是服务器用来保存用户操作的一系列会话信息,由Web容器进行管理.最常见的,会把用户的登录信息.用户信息存储在 session 中,以保持登录状态. ...

  2. iOS提示框,为什么你应该使用 MBProgressHUD?

    这是一篇带有一定笔者主观感情色彩的比较文章.文章着重对比github上最流行的两个iOS进度提示控件 MBProgressHUD 与 SVProgressHUD的各自优劣,来帮助初学者找到一个适合的i ...

  3. ssm整合-错误

    [Err] 1005 - Can't create table 'imoocdb.ec_article' (errno: 150) 这个错误由外键约束引起的 java.lang.ClassCastEx ...

  4. spring cloud 学习之服务消费者(Feign)

    一.Feign简介 Feign是一个声明式的伪Http客户端,它使得写Http客户端变得更简单.使用Feign,只需要创建一个接口并注解.它具有可插拔的注解特性,可使用Feign 注解和JAX-RS注 ...

  5. sql server几种Join的区别测试方法与union表的合并

    /* sql server几种Join的区别测试方法 主要来介绍下Inner Join , Full Out Join , Cross Join , Left Join , Right Join的区别 ...

  6. java常量池概念【转】

    http://blog.csdn.net/olanlanxiari/article/details/8104505

  7. linux防火墙的管理和策略控制

    iptables 一:IPtables防火墙的简介 IPTABLES 是与最新的 3.5 版本 Linux 内核集成的 IP 信息包过滤系统.如果 Linux 系统连接到因特网或 LAN.服务器或连接 ...

  8. redis安装与简单使用

    第一步 新建一个文件 第二步 利用winscrp软件从本机上传redis的压缩包到linux新建的rdtar目录 第三步   cd rdtar 第四步   解压  tar zxvf redis-2+t ...

  9. [BZOJ4196]软件包管理器(树链剖分)

    [BZOJ4196] install x-> 询问根节点到x路径上0的个数,然后全变1 uninstall x-> 询问x子树(包括x)中1的个数,然后全边0 Code #include ...

  10. 笔记-python-多环境-virtualenv

    笔记-python-多环境-virtualenv 1.      多环境 在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.6.4,所有第三方的包都会被pip安装到Pytho ...