HDU 4474 Yet Another Multiple Problem bfs枚举所有余数
来源:互联网 发布:java ant 编译命令 编辑:程序博客网 时间:2024/04/29 13:08
题意:给一个数n,和m个十进制个位数,问n的最小倍数是多少,前提是最小倍数里面没有这m个数。
想法:首先不管是暴力还是怎么写,都会有一个限制,那就是什么时候表示如果再扩大也不会再有n的倍数且满足的数了,那么此时输出-1,需要找到这个临界点。如果现在用很多位数组成了一个新的数,如果这个数%n的余数出现过,那么他就没有必要再继续下去了,如果n的所有余数都出现了除了0,还是找不到,那么显然就不存在解了。
pair<string,int>pq;
string a用c语言输出为:printf("%s",a.c_str());
#include<iostream>#include<cstdio>#include<queue>#include<cstring>#include<string>using namespace std;const int nodes=10000+5; int n,m;bool vis[nodes],noused[10];string bfs(){queue<pair<string,int> >q;while(!q.empty()) q.pop();pair<string,int>head,nxt,init;init.first="";init.second=0;q.push(init);while(!q.empty()){head=q.front();for(int i=0;i<10;i++){if(head.first.length()==0&&i==0) continue;if(noused[i]) continue;char p='0'+i;string kk=head.first+p;int x=(head.second*10+i)%n;if(!vis[x]){if(!x){return kk;}vis[x]=true;nxt.first=kk;nxt.second=x;q.push(nxt);}}q.pop();}return "-1";}int main(){int ca=1;while(~scanf("%d%d",&n,&m)){memset(vis,false,sizeof(vis));memset(noused,false,sizeof(noused));for(int i=1;i<=m;i++){int a;scanf("%d",&a);noused[a]=true;}printf("Case %d: ",ca++);printf("%s\n",bfs().c_str());}return 0;}
0 0
- 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)
- HDU 4474 Yet Another Multiple Problem BFS
- [bfs+余数判重+路径记录] 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+mod运算)
- HDU 4474 Yet Another Multiple Problem(搜索 BFS)
- HDU 4474 Yet Another Multiple Problem【BFS+一个判断技巧】
- hdu 4474 Yet Another Multiple Problem ( bfs + math)
- hdu 4474 Yet Another Multiple Problem(BFS)
- HDU-#4474 Yet Another Multiple Problem(BFS)
- HDU 4474(Yet Another Multiple Problem)(BFS+同余定理)
- Yet Another Multiple Problem-----BFS
- HDU 4474 Yet Another Multiple Problem(数位搜索+余数剪枝)
- 中文分词算法
- React入门教程(二)
- IOS开发编码规范
- Sql语句(关于基本表)
- MyCAT简易入门
- HDU 4474 Yet Another Multiple Problem bfs枚举所有余数
- 天声人語 20160322 88年ぶりの歴史的訪問
- Go语言配置文件解析器,类似于Windows下的INI文件.
- 日经春秋 20160322
- CSS学习(十九)-CSS伸缩布局盒
- 在安卓开发时用酷派手机无法打印出应用内的日志的解决办法
- vi备忘录
- HTTP_USER_AGENT
- 今日BBC