【搜索】 HDU 4474 Yet Another Multiple Problem
来源:互联网 发布:linux setfacl 编辑:程序博客网 时间:2024/06/05 09:25
点击打开链接
题意 : 求一个最小的n的倍数 ans,使得ans不包括 输入的几个数字 ,不存在输出 -1
思路 :对于 两个数 A , B 存在 A > B 且 A%n = B%n 则 (A*10 + K ) %n = (B*10 + K ) %n 然而 A*10 + K 仍然 大于 B*10 + K
所以就不需要搜 A 了 ,判断 余数 是否出现过 在剪枝
ans 会很大 所以用字符串模拟
类似: HDU 1226
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <string>#include <iostream>#include <algorithm>using namespace std;#include <queue>#include <stack>#include <vector>#include <bitset>#include <deque>#include <set>#pragma comment(linker, "/STACK:1024000000,1024000000")#include <map>typedef long long LL;typedef unsigned long long ULL;const int INF = 1<<29;const LL mod = 1e9+7;const int MAXN = 100100;//点数的最大值const int MAXM = 520;//边数的最大值const double pi = acos(-1);int a[21213],m;ULL n;bool vis[22344];struct node{ string ans; int mmm;};queue<node>q;string gao(){ while(!q.empty()) q.pop(); node fro; fro.ans="";fro.mmm=0; q.push(fro); while(!q.empty()) { node x=q.front(); q.pop(); for(int i=0;i<=9;i++) { if(a[i]) continue; if(x.mmm==0&&i==0) continue; fro.mmm=(x.mmm*10+i)%n; if(vis[fro.mmm]) continue; vis[fro.mmm]=1; fro.ans=x.ans+(char)('0'+i); if(fro.mmm==0) return fro.ans; q.push(fro); } } return "-1";}int main(){ int cas=0; while(scanf("%I64u%d",&n,&m)!=EOF) { memset(a,0,sizeof(a)); for(int i=0;i<m;i++) { int x; scanf("%d",&x); a[x]=1; } memset(vis,0,sizeof(vis)); string ans=gao(); printf("Case %d: ",++cas); cout<<ans<<endl; } return 0;}
0 0
- 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(搜索 BFS)
- HDU 4474 Yet Another Multiple Problem(搜索剪枝)
- HDU---4474 Yet Another Multiple Problem【广度优先搜索】
- 【搜索】 HDOJ 4474 Yet Another Multiple Problem
- 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 (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
- Microsoft Visual C++ 6.0快捷键(绝对值得掌握)
- IOS中获取各种文件的目录路径的方法
- HDU 3729 I'm Telling the Truth(2010 Asia Tianjin Regional Contest )
- nyoj 448 寻找最大数
- 空格替换
- 【搜索】 HDU 4474 Yet Another Multiple Problem
- IOS的app程序中的文件目录的功能和使用详细说明 - 包括itune同步的部分
- Android的Activity滑动切换动画
- 前序为ABC,后序为CBA的二叉树共有多少棵
- PHP 学习2
- XSD、dtd不联网情况下可能出现的报错。
- java笔试题 2
- eclipse 的重构使用
- 深入理解 [NSBundle mainBundle]