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 ...
随机推荐
- Entity Framework 并发处理借鉴
如下博客 http://www.cnblogs.com/Bce-/p/3725868.html
- Silverlight C#动态设置样式
1.从页面资源中获取样式并应用 btnTest.Style = (Style)this.Resources["BigButtonStyle"] 2.从项目中单独分开的资源字典文件( ...
- [大牛翻译系列]Hadoop(17)MapReduce 文件处理:小文件
5.1 小文件 大数据这个概念似乎意味着处理GB级乃至更大的文件.实际上大数据可以是大量的小文件.比如说,日志文件通常增长到MB级时就会存档.这一节中将介绍在HDFS中有效地处理小文件的技术. 技术2 ...
- CSS3 animation小动画
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 防DDOS攻击
/ip firewall filter add chain=forward connection-state=new action=jump jump-target=block-ddos add ch ...
- How to understand ReferenceGroup control on Form[AX2012]
在AX2012的Form开发中,微软引入了新的控件ReferenceGroup,它用在Lookup其他表RecId的时候显示更人性化的字段,它的使用还必须从表的索引说起.AX2012的表有这些索引(h ...
- PyQt4学习笔记1:PyQt4第一个程序
创建一个 PyQt4 一般可以通过很少的步骤完成.通常的方法是用Qt 提供的QtDesigner工具创建界面.使用QtDesigner,可以方便地创建复杂的GUI界面.然后,可以在窗口上创建部件, 添 ...
- 1. opencv的初体验
http://guoming.me/opencv-config 这篇文章有讲解opencv的安装与配置 一些常用库 opencv_core249d.lib opencv_imgproc249d.li ...
- 1096. Consecutive Factors (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- Apache网站根目录
Apache环境配置好了,把项目放到网站根目录下的htdocs文件夹下,运行网站的时候不需要加上该文件夹的名称,Apache直接在上面找对应的项目