2012ICPC长春站 K Yet Another Multiple Problem 【BFS+同余模定理】
来源:互联网 发布:淘宝网刷销量 编辑:程序博客网 时间:2024/06/05 18:11
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?
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.
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 3
7 8 9
100 1
0
Sample Output
Case 1: 2345
Case 2: -1
Source
2012 Asia Chengdu Regional Contest
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<iomanip>#include<string>#include<vector>#include<stack>#include<queue>#include<cmath>#include<functional>using namespace std;#define LL long long int #define INF 0x3f3f3f3fconst int maxn = 1e5 + 10;const int MOD = 1e9 + 7;struct point{ int m, f; char c;}ans[maxn], temp;int n, m, l, r;bool k[10], h[maxn];void pout(int x)//递归输出{ if (x == -1) return; pout(ans[x].f); putchar(ans[x].c);}int main(){ int tm = 0; int tmp; while (cin >> n >> m) { tm++; memset(h, true, sizeof(h)); memset(k, true, sizeof(k)); l = 0; r = 0; for (int i = 0; i < m; i++) { cin >> tmp; k[tmp] = 0; } int answer = -1; for (int i = 1; i < 10; i++) { if (k[i]) { temp.c = i + '0'; temp.m = i%n; h[temp.m] = 0; temp.f = -1; ans[r++] = temp; if (temp.m == 0) { answer = r - 1; break; } } } while (l < r&&answer == -1) { for (int i = 0; i < 10; i++) { if (k[i]) { temp.c = i + '0'; temp.m = (ans[l].m * 10 + i) % n; if (h[temp.m]) { h[temp.m] = 0; temp.f = l; ans[r++] = temp; if (temp.m == 0) { answer = r - 1; break; } } } } l++; } cout << "Case " << tm << ": "; if (answer == -1) cout << "-1" << endl; else { pout(answer); cout << endl; } } return 0;}
- 2012ICPC长春站 K 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)同余模定理·
- 解题报告:HDU4474 Yet Another Multiple Problem BFS + 同余剪枝
- Yet Another Multiple Problem-----BFS
- 2012ACM/ICPC成都赛区现场赛K题---Yet Another Multiple Problem(hdu4474)
- 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 BFS+同余判重 ★★★★
- poj 1426 Find The Multiple ( BFS+同余模定理)
- POJ 1426 Find The Multiple(BFS 同余模定理)
- poj 1426 Find The Multiple bfs+同余模定理
- poj_1426 Find The Multiple(bfs + 同余模定理)
- POJ 1426 Find The Multiple(BFS+同余模定理)
- POJ 1465 Multiple (BFS,同余定理)
- codeforces 858b
- 代理模式
- noip2008 传纸条 T3题解
- Java利用POI导出Excel设置单元格格式
- 筛选合理的关键词以及网站雏形布局
- 2012ICPC长春站 K Yet Another Multiple Problem 【BFS+同余模定理】
- 利用springmvc提供一个HandlerExceptionResolver接口实现出错返回Json数据
- 移动架构09_Activity的启动流程分析
- Qt中QComboBox下拉列表(popup)位置与样式的控制
- h5音频视频播放
- 数据结构-堆栈-链表实现
- 蓝桥杯 算法提高 连接乘积
- 【二】Java基础语法整理
- noip2000 方格取数 T4