【搜索】 HDU 1664 Different Digits
来源:互联网 发布:网络中介怎么做的 编辑:程序博客网 时间:2024/05/16 05:09
//对于任意的整数n,必然存在一个由不多于两个的数来组成的一个倍数。
。。。所以最多有2个数字
先判断1个数字的情况没有再判断2个数字的情况
在s串上每次添加1个数判断是否被n整除
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <math.h>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#include <set>#include <map>#define cler(arr, val) memset(arr, val, sizeof(arr))#define IN freopen ("in.txt" , "r" , stdin);#define OUT freopen ("out.txt" , "w" , stdout);typedef long long LL;const int MAXN = 66666;//点数的最大值const int MAXM = 20006;//边数的最大值const int INF = 1101521204;const int mod = 10000007;int num[MAXN],ans,n;int pre[MAXN],re[MAXN],out[MAXN];string s;void print(int x){ if(x!=-1) print(pre[x]); else return ; s+=(out[x]+'0');}string bfs(int x,int y){ s=""; int tol=0; cler(num,0); if(x!=0) { pre[tol]=-1; out[tol]=x; num[x%n]=1; re[tol++]=x%n; } if(!num[y%n]) { pre[tol]=-1; out[tol]=y; num[y%n]=1; re[tol++]=y%n; } for(int i=0; i<tol; i++) { if(re[i]==0) { print(i); return s; } else { int temp=re[i]*10+x; if(!num[temp%n]) { pre[tol]=i; out[tol]=x; num[temp%n]=1; re[tol++]=temp%n; } temp=re[i]*10+y; if(!num[temp%n]) { pre[tol]=i; out[tol]=y; num[temp%n]=1; re[tol++]=temp%n; } } } return s;}bool cmp(string temp,string ans){ if(temp.size()!=ans.size()) { return temp.size()<ans.size(); } return temp<ans;}int main(){ //IN; while(scanf("%d",&n),n) { string ans="",temp; for(int i=1; i<=9; i++) { temp=bfs(i,i); //cout<<temp<<endl; if(temp.size()==0) continue; if(ans.size()==0||cmp(temp,ans)) ans=temp; } // cout<<ans<<endl; if(ans.size()==0) { for(int i=0; i<=9; i++) { for(int j=i+1; j<=9; j++) { temp=bfs(i,j); // cout<<temp<<endl; if(temp.size()==0) continue; if(ans.size()==0||cmp(temp,ans)) ans=temp; // cout<<ans<<i<<j<<endl; } } } cout<<ans<<endl; }}
0 0
- 【搜索】 HDU 1664 Different Digits
- 【hdu】1664 different digits【搜索+字符串处理】
- hdu 1664 Different Digits
- HDU 1664 Different Digits
- HDU 1664 Different Digits
- hdu Different Digits 1664
- hdu 1664 Different Digits
- HDU-1664-Different Digits(BFS)
- hdu1664 Different Digits (搜索)
- HDU 1664 Different Digits (数论 -- 鸽笼原理 + BFS搜索 + 余数判重)
- HDU 1664 POJ 2283 Different Digits
- 【POJ 2283】 【HDU 1664】 Different Digits
- hdu1664 Different Digits (搜索)
- HDOJ 1664 Different digits
- hdu 1664 Different Digits (bfs+取余判重+数论知识)
- BFS+余数判重+数论 hdu-1664-Different Digits
- hdu 1664 Different Digits, spoj 3929 , 同余,bfs
- hdu 1664 Different Digits(bfs+余数判重)
- 野指针
- 面试题&笔试题:求1+x+x^2+x^3+...+x^n的和(尽可能少的使用乘法运算)
- hive大数据倾斜总结
- java Object类源代码详解
- Oracle的sys和system默认密码
- 【搜索】 HDU 1664 Different Digits
- cas入门之二十九:cas 集群简介
- 关于覆盖BIN来升级client的问题
- 函数的使用——根据传入的值,打印出相应的矩形。
- 关于Token的简要理解
- poj 3070 矩阵快速幂简单题
- Python装饰器学习(九步入门)
- 在ubuntu中配置中文版man手册
- HDU 1003 Max Sum(最大子列和)