题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=530
我的方法是直接利用BFS暴力搜索
我的代码:
Source
Problem Id:1690User Id:bingshen
Memory:4276KTime:953MS
Language:G++Result:Accepted
- Source
#include<stdio.h> #include<queue> #include<algorithm> using namespace std; __int64 ans[300]; bool used[300]; void init() { __int64 now,i,num=0; memset(used,0,sizeof(used)); queue<__int64>q; q.push(1); while(!q.empty()) { now=q.front(); q.pop(); for(i=1;i<=200;i++) { if(!used[i]&&now%i==0) { ans[i]=now; used[i]=true; num++; } } if(num==200) break; now=now*10; q.push(now); now=now+1; q.push(now); } } int main() { __int64 n; init(); while(scanf("%I64d",&n)!=EOF) { if(n==0) break; printf("%I64d/n",ans[n]); } return 0; }不过还好953MS卡过去了。。但是如果过不了的话,可以直接利用刚刚的程序打一个表出来,因为反正n不大
本文介绍了一种使用广度优先搜索(BFS)解决ZJU ACM 1690问题的方法,并提供了一份通过该方法成功解决问题的C++代码示例。
412

被折叠的 条评论
为什么被折叠?



