hdu 4474 Yet Another Multiple Problem
题意:
找到一个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 ;
}
广搜,同余剪枝
B=NX+R
假设A,B对于X的余数相同
那么
(10*A+d[i])%x
(10*B+d[i])%x
的意义是一样的,所以只有当余数没出现过的情况下才加入到搜索的队列中来
hdu 4474 Yet Another Multiple Problem的更多相关文章
- 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 ( BFS + 同余剪枝 )
没什么巧办法,直接搜就行. 用余数作为每个节点的哈希值. #include <cstdio> #include <cstring> #include <cstdlib&g ...
- HDU 4474 Yet Another Multiple Problem BFS
题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0 1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...
- 2012Chhengdu K - Yet Another Multiple Problem
K - Yet Another Multiple Problem Time Limit:20000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 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 ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- Yet Another Multiple Problem(bfs好题)
Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other) Memory Limit : 65536/65536K ( ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
- hdu4474 Yet Another Multiple Problem
Yet Another Multiple Problem Description There are tons of problems about integer multiples. Despite ...
随机推荐
- yum安装报错有冲突file /usr/lib64/php/modules/fileinfo.so conflicts between
yum安装报错有冲突file /usr/lib64/php/modules/fileinfo.so conflicts between attempted installs of php-pecl-f ...
- oracle 文件导出
$ cat me.sqlset echo offset term offset line 1000 pages 0set feedback offset heading offset trimspoo ...
- Hadoop上路-04_HBase0.98.0入门
以下操作在Hadoop分布式集群基础上进行. 一.分布式环境搭建 下载:)验证 3)修改%HBASE%/conf/hbase-env.sh 4)修改$HBASE_HOME/conf/hbase-sit ...
- PHP 登录完成后如何跳转上一访问页面
访问网站页面时,有的页面需要授权才能访问,这时候就会要求用户登录,跳转到登录页面login.php,怎么实现登录后返回到刚才访问的页面 项目需求 访问网站页面时,有的页面需要授权才能访问,这时候就会要 ...
- ASP专栏——ASP生成静态文件(用于大量文章)
对于Web开发人员来说,生成静态文件这个概念并不陌生. 对于Web开发来说,如何能避免客户端访问时不停的查询数据库?现在比较常用的有两种方法,一种是使用缓存技术,将查询出来的结果缓存至缓存框架中,以后 ...
- CLR via C# I/O基元线程同步构造
1. 分为用户模式构造和内核模式构造 2. 用户模式构造 a.易失构造 在一个简单数据类型的变量上执行原子性读或写操作 VolaileWrite 强制address中的值在调用时写入,除此之外,按照源 ...
- How to force to Fullscreen Form
Is it possibile by code resize a form to fullscreen? (like button Maximize) ? // VAR Changed on 10 J ...
- How to modify Code Comments[AX2012]
// This is a framework class. Customizing this class may cause problems with future upgrades to the ...
- ssh-keygen实现免密码登陆
在 Client 端建立 Public 与 Private Key : 建立的方法真的是简单到不行!直接在 192.168.0.100 这个 Client 上面,以 test2 这个账号,使用 ssh ...
- 修改info
新增Key: NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription ,这两个Key的值将分别用于描述应用程序 ...