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 ...
随机推荐
- 使用RGBa和Filter实现不影响子元素的CSS透明背景
点击查看原文 问题 如果我们想要一个元素拥有半透明的背景,我们有两个选择: 使用CSS和 opacity 做一张 24-bit PNG 背景图片 在CSS中使用opacity有两个问题,一是为了适应所 ...
- SecureCRT上传bash: rz: command not found
SecureCRT上传bash: rz: command not found -bash: rz: command not found rz命令没找到? 执行sz,同样也没找到. 安装lrzs ...
- iOS开发——实时监控网速(仅作参考,发现一点问题)
开发中用到获取网速的地方,应该就两种: 1.下载速度,这种可以直接在接受数据的地方统计计算.这个就不讲了. 2.获取手机网卡的数据,可以监控网卡的进出流量,下面就是. #import "Vi ...
- 基于keepalived 实现VIP转移,lvs,nginx的高可用
转自:http://www.tuicool.com/articles/eu26Vz 一.Keepalived 高可用集群的解决方案 二.VRRP的有限状态机 三.利用keepalived 实现主从VI ...
- tinyxml2库的使用--MFC工程
在编写应用程序的时候,经常需要动态加载某些数据,这种情况下微软的ini文件是蛮好的选择,但是平台的通用性比较差,使用xml的话就比较强一点,但是解析比较复杂,型号有牛人已经开发出了直接读写xml的库, ...
- HUST 1372 marshmallow
很简单的博弈题.....算几组能得到规律了. 某个状态先手要赢 等价于 之前有一种状态是后手赢,先手可以保证让现在这个状态到达那个状态 #include<cstdio> #include& ...
- 对float的理解
从IE6下的双边距引出 对一个div设置float:left;同时设置了margin-left:100px时在IE6下会出现双边距. 有两种解决办法: 1,推荐办法.加display:inline 2 ...
- Online Schema Change for MySQL
It is great to be able to build small utilities on top of an excellent RDBMS. Thank you MySQL. This ...
- sublime text2的插件熟悉
今天加班,开会.于是整理下sublime text的插件. 1.安装了tag插件.负责html的格式化.从百度云下载了文件,放入了插件包的目录下. 2.启用了alignment 快捷键 ctr+alt ...
- android——网络操作(一)连接网络
连接网络 一,包含许可 <uses-permissionandroid:name="android.permission.INTERNET"/> <uses-pe ...