解题报告:HDU4474 Yet Another Multiple Problem BFS + 同余剪枝
来源:互联网 发布:ipadpro下载软件流程 编辑:程序博客网 时间:2024/06/05 08:29
Yet Another Multiple Problem
Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 5472 Accepted Submission(s): 1251
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
#include<bits/stdc++.h>using namespace std;int n,m;bool used[10];struct state { int last; int mod ; int f ;}S[100005];bool has[10005];queue<int>Q;inline void out(int x){ if(~S[x].f)out(S[x].f); printf("%d",S[x].last);}int main(){ int t = 0; while(scanf("%d%d",&n,&m)==2){ memset(used,false,sizeof(used)); memset(has,false,sizeof(has)); for(int i=0,x;i<m;i++){ scanf("%d",&x); used[x] = true; }while(!Q.empty())Q.pop(); int all = 0;int head = -1; for(int i=1;i<10;i++){ if(!used[i]){ S[all].last = i; S[all].mod = i % n; S[all].f = -1; has[S[all].mod] = true; if(S[all].mod==0){ head = all; break; } Q.push(all++); } } while(!Q.empty()&&head==-1){ int x = Q.front();Q.pop(); for(int i=0;i<10;i++){ if(!used[i]){ S[all].last = i; S[all].mod = ( S[x].mod * 10 + i ) % n; S[all].f = x; if(!has[S[all].mod]){ has[S[all].mod] = true; if(S[all].mod==0){ head = all; break; }Q.push(all++); } } } } printf("Case %d: ",++t); if(head==-1){ printf("-1\n"); }else { out(head); printf("\n"); } }return 0;}
0 0
- 解题报告:HDU4474 Yet Another Multiple Problem BFS + 同余剪枝
- HDU 4474 Yet Another Multiple Problem(bfs+同余模定理剪枝)
- HDU 4474(Yet Another Multiple Problem)(BFS+同余定理)
- hdu4474-Yet Another Multiple Problem
- hdu4474 Yet Another Multiple Problem
- HDU4474 Yet Another Multiple Problem
- 2012ICPC长春站 K Yet Another Multiple Problem 【BFS+同余模定理】
- HDOJ 4474 Yet Another Multiple Problem(BFS + 剪枝)
- Yet Another Multiple Problem-----BFS
- hdu 4474 Yet Another Multiple Problem bfs
- hdu 4474 Yet Another Multiple Problem (bfs)
- hdu 4474 Yet Another Multiple Problem(BFS)
- HDU 4474 Yet Another Multiple Problem BFS
- HDU 4474 (Yet Another Multiple Problem)同余模定理·
- POJ 1465 Multiple(BFS+同余剪枝)
- hdu 4474 Yet Another Multiple Problem BFS+同余判重 ★★★★
- 【HDU4474 2012成都现场赛K】【搜索-BFS】Yet Another Multiple Problem 最小的要求字符集的数字倍数 余数哈希BFS
- Yet Another Multiple Problem
- namp
- hdu4458Shoot the Airplane+计算几何
- Ubuntu虚拟机下网络分享
- 顺序表应用5:有序顺序表归并
- Linux基本命令练习(9)---grep
- 解题报告:HDU4474 Yet Another Multiple Problem BFS + 同余剪枝
- 矩阵的压缩存储
- 九个PHP很有用的功能
- imx6q处理器,linux操作系统平台搭建 从eMMC启动系统
- Linux下find查找命令用法
- ios 支付宝编译时找不到 openssl/asn1.h 文件
- iOS开发:Compile Sources(编译来源)与 Copy Bundle Resources(资源文件)
- python解析torrent文件库:pytorrent
- Lightoj 1008 - Fibsieve`s Fantabulous Birthday