HDU4474
Yet Another Multiple Problem
Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 5496 Accepted Submission(s): 1257
Problem Description
In this problem, you’re asked to solve the following question: Given a positive integer n and m decimal digits, what is the minimal positive multiple of n whose decimal notation does not contain any of the given digits?
Input
For each test case, there are two lines. The first line contains two integers n and m (1 ≤ n ≤ 104). The second line contains m decimal digits separated by spaces.
Input is terminated by EOF.
Output
Sample Input
Sample Output
//2016.9.5
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define N 10005 using namespace std; bool vis[N], del[];//vis表示是否访问过,del表示不能出现的数字
int n, m, pre[N];
char text[N];//最后输出的数组 bool bfs()
{
queue<int> q;
q.push();
int cur;
while(!q.empty())
{
cur = q.front();
q.pop();
for(int i = ; i < ; i++)
{
if(del[i]==true||cur==&&i==)continue;//不符合要求
int mod = (cur*+i)%n;
if(vis[mod])continue;//剪枝
text[mod] = ''+i;
vis[mod] = true;
pre[mod] = cur;//记录上一个节点
q.push(mod);
if(mod == )return true;
}
}
return false;
} void print()//打印路径
{
string ans;
int pos = ;
while(pos!= || ans.empty())
{
ans += text[pos];
pos = pre[pos];
}
reverse(ans.begin(), ans.end());//翻转,输出
puts(ans.c_str());
} int main()
{
int kase = , x;
while(scanf("%d%d", &n, &m)!=EOF)
{
memset(vis, , sizeof(vis));
memset(del, , sizeof(del));
for(int i = ; i < m; i++)
{
scanf("%d", &x);
del[x] = true;
}
printf("Case %d: ", ++kase);
if(!bfs())printf("-1\n");
else print();
} return ;
}
HDU4474的更多相关文章
- hdu4474 Yet Another Multiple Problem
Yet Another Multiple Problem Description There are tons of problems about integer multiples. Despite ...
随机推荐
- Ubuntu Server 14.04 & Apache2.4 虚拟主机、模块重写、隐藏入口文件配置
环境: Ubuntu Server 14.04 , Apache2.4 一.Apache2.4 虚拟主机配置 01. 新建一份配置文件 在apache2.4中,虚拟主机的目录是通过/etc/apach ...
- ecos的app机制
底层->支持层->业务 底层base 数据库访问 service管理 app管理 kvstore存储 kvcache缓存 支持层 pam登录验证 dbeav数据库扩展功能 site前台 d ...
- Java笔记——XML解析
import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import ja ...
- CentOS 6.X x64 编译安装 Countly
CentOS 6.X x64 编译安装Countly 安装所需的软件 yum -y install supervisor ImageMagick sendmail 1. 安装 node.js wge ...
- tcpdump的表达元
(nt: True 在以下的描述中含义为: 相应条件表达式中只含有以下所列的一个特定表达元, 此时表达式为真, 即条件得到满足) dst host host如果IPv4/v6 数据包的目的域是host ...
- Spring自学教程-AOP学习(五)
Spring中的AOP 一.概述 (一)基本概念 1.什么是AOP? 面向方面编程.所谓方面即是指日志.权限.异常处理.事务处理等. 2.AOP的3个关键概念 (1)切入点(Pointc ...
- Extjs4中的常用组件:Grid、Tree和Form
至此我们已经学习了Data包和布局等API.下面我们来学习作为Extjs框架中我们用得最多的用来展现数据的Grid.Tree和Form吧! 目录: 5.1. Grid panel 5.1.1. Col ...
- Android L(5.0)源码之图形与图像处理之简单图片——Bitmap
最近在研究android 5.0的gallery模块,学习了相关的知识点,准备写点博客总结一下,有时间了会补充完整
- 502 Bad Gateway(Nginx) 查看nginx日志有如下内容
2016/09/01 09:49:41 [error] 79464#79464: *3 user "nagios" was not found in "/usr/loca ...
- Qt下libusb-win32的使用(转)
源:Qt下libusb-win32的使用(一)打印设备描述符 主要是在前一篇的基础上,学习libusb-win32的API使用.程序很简单,就是打印指定USB设备的设备描述符(当然其他描述符也是可以的 ...