HDU 4474 Yet Another Multiple Problem
来源:互联网 发布:浙江师范行知学院 编辑:程序博客网 时间:2024/06/05 11:34
Yet Another Multiple Problem
Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 6289 Accepted Submission(s): 1458
Problem Description
There are tons of problems about integer multiples. Despite the fact that the topic is not original, the content is highly challenging. That’s why we call it “Yet Another Multiple Problem”.
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?
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
There are several test cases.
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.
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
For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) while Y is the minimal multiple satisfying the above-mentioned conditions or “-1” (without quotation marks) in case there does not exist such a multiple.
Sample Input
2345 37 8 9100 10
Sample Output
Case 1: 2345Case 2: -1
Source
2012 Asia Chengdu Regional Contest
Recommend
liuyiding | We have carefully selected several similar problems for you: 6216 6215 6214 6213 6212
My ugly code
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <iostream>#include <queue>using namespace std;const int maxn=1e4+10;int n,m;int a[maxn];bool del[10],vis[maxn];/*del用于记录哪个数据可以用,vis记录余数,出现过的就不再重复出现*/int pre[maxn];/*记录前驱,方便输出*/char text[maxn];/*记录走过的值*/int cas=1;bool bfs(){ queue<int> q; while(!q.empty()) q.pop(); memset(pre,-1,sizeof(pre)); memset(vis,false,sizeof(vis)); q.push(0); int cur; while(!q.empty()){ cur=q.front(); q.pop(); for(int i=0;i<=9;i++){ if(del[i] || cur==0&&i==0) continue ; int yu=(cur*10+i)%n; if(vis[yu]) continue ; vis[yu]=true; q.push(yu); text[yu]='0'+i; pre[yu]=cur; if(yu == 0){ return true; } } } return false;}void out(){ char pout[maxn]; int cnt=0; int cur=0; pout[cnt++]=text[cur]; cur=pre[cur]; while(cur != 0){ pout[cnt++]=text[cur]; cur=pre[cur]; } pout[cnt]='\0'; printf("%s\n",_strrev(pout));}int main(){ while(~scanf("%d%d",&n,&m)){ int tmp; memset(del,false,sizeof(del)); for(int i=1;i<=m;i++){ scanf("%d",&tmp); del[tmp]=true; } bool ans=bfs(); printf("Case %d: ",cas++); if(ans) out(); else printf("-1\n"); } return 0;}
阅读全文
0 0
- Yet Another Multiple Problem (hdu 4474)
- HDU 4474 Yet Another Multiple Problem
- hdu 4474 Yet Another Multiple Problem bfs
- HDU 4474 Yet Another Multiple Problem
- HDU 4474 Yet Another Multiple Problem 搜索
- HDU 4474 Yet Another Multiple Problem
- hdu 4474 Yet Another Multiple Problem (bfs)
- hdu 4474 Yet Another Multiple Problem(BFS)
- 【搜索】 HDU 4474 Yet Another Multiple Problem
- HDU 4474 Yet Another Multiple Problem
- hdu 4474 Yet Another Multiple Problem
- Hdu 4474 Yet Another Multiple Problem
- HDU 4474:Yet Another Multiple Problem
- HDU 4474 Yet Another Multiple Problem BFS
- HDU 4474 Yet Another Multiple Problem
- HDU 4474 Yet Another Multiple Problem
- hdu 4474 Yet Another Multiple Problem 模型转换 BFS搜索
- HDU 4474 Yet Another Multiple Problem 搜索——BFS
- 001_LeetCode_1 Two Sum 题解
- webstorm开发Cordova App
- java使用SAX接口解析xml文件
- C++中的数据类型转换运算符
- Qt-Paint系统
- HDU 4474 Yet Another Multiple Problem
- bzoj 1899: [Zjoi2004]Lunch 午餐
- 怎么把图片转换成BMP格式
- 虽然微不足道但是很有用的JAVA基础—数组
- [BZOJ]1899: [Zjoi2004]Lunch 午餐 DP
- STL库中的stack和queue及其模拟实现
- springmvc学习笔记(19)-RESTful支持
- 类加载
- Java的值传递,没有引用传递