hdu 4474 Yet Another Multiple Problem(按位枚举,4级)
来源:互联网 发布:过目不忘 知乎 编辑:程序博客网 时间:2024/05/16 06:39
Yet Another Multiple Problem
Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1754 Accepted Submission(s): 435
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
模数最多10000 所以最多产生10000个数。
#include<cstdio>#include<cstring>#include<iostream>#define FOR(i,a,b) for(int i=a;i<=b;++i)#define clr(f,z) memset(f,z,sizeof(f))using namespace std;const int mm=5e5+9;class bit{ public:int c,sum,fa;}Q[mm];int l,r;bool ten[11],vis[mm],flag;int n,m;void out(int x){ if(Q[x].fa!=-1) out(Q[x].fa); printf("%d",Q[x].c);}void getans(){ int ret; l=0,r=0;flag=0; FOR(i,1,9) if(!ten[i]) { Q[r].c=i;Q[r].sum=i%n;Q[r].fa=-1; ret=Q[r].sum;++r; vis[ ret ]=1; if(ret==0) { flag=1;//puts("yes");cout<<i<<endl; out(r-1);return; } } while(l<r) { FOR(i,0,9) if(!ten[i]) { Q[r].c=i;Q[r].sum=(Q[l].sum*10+i)%n;Q[r].fa=l; ret=Q[r].sum; if(ret==0){out(r);flag=1;return;} if(!vis[ ret ]){++r;vis[ret]=1;} } ++l; }}int main(){ int a,cas=0; while(~scanf("%d%d",&n,&m)) { clr(ten,0); clr(vis,0); printf("Case %d: ",++cas); FOR(i,1,m) { scanf("%d",&a); ten[a]=1; } getans(); if(flag)puts(""); else puts("-1"); }}
- hdu 4474 Yet Another Multiple Problem(按位枚举,4级)
- HDU 4474 Yet Another Multiple Problem bfs枚举所有余数
- 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
- TCP/IP网络层
- 一个简单线程池的实现
- hdu 4617 Weapon 计算异面直线间距离
- 详解大端模式和小端模式
- 关于Mybatis的研究之 bean没有set方法 也可以赋值
- hdu 4474 Yet Another Multiple Problem(按位枚举,4级)
- Socket编程
- poj2299 Ultra-QuickSort
- 二叉树的前序中序后序遍历 - 递归&非递归版本
- Difference between Setter Injection vs Constructor Injection in Spring framework
- CRectTracker(橡皮筋)类的使用
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text) (指针的"思想")
- tcp校验和 csum_block_add 和csum_block_sub函数
- linux yum命令详解